您好,登錄后才能下訂單哦!
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();
/**
* 利用過(guò)濾字段進(jìn)行過(guò)濾掉制定的字符串
* */
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) {
}
});
}
}
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。