您好,登錄后才能下訂單哦!
public class MainActivity extends Activity {
private EditText edit;
private ListView list;
private String[] str = new String[] { "1232", "45", "4631", "123485",
"87894", "4156", "1564", "5465", "45612", "98", "1247", "59789",
"7897862", "578631", "48876", "215", "2148", "7985" };
ArrayAdapter adapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.item);
edit = (EditText) findViewById(R.id.edit);
list = (ListView) findViewById(R.id.list);
adapter = new ArrayAdapter(MainActivity.this, R.layout.window,
R.id.text, str);
list.setAdapter(adapter);
edit.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View arg0, int keyCode, KeyEvent KeyEvent) {
if (keyCode == KeyEvent.KEYCODE_DEL) {
/**
* 每次刪除即使更新list列表
* */
EditText edit = (EditText) arg0;
adapter.getFilter().filter(edit.getText().toString());
adapter.notifyDataSetChanged();
}
return false;
}
});
edit.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
// String str_new = s.toString();
/**
* 利用過濾字段進行過濾掉制定的字符串
* */
adapter.getFilter().filter(s);
adapter.notifyDataSetChanged();
}
@Override
public void beforeTextChanged(CharSequence s, int start, int end,
int count) {
}
@Override
public void onTextChanged(CharSequence s, int start, int end,
int count) {
}
});
}
}
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。