我在我的活动中扩展ListActivity
并绑定ListView
。应用过滤器到listview。使用emulater时过滤器工作正常,因为我有笔记本电脑的键盘。但是当我想在android上过滤数据时问题就出现了,因为它没有向我显示键盘。代码如下。
String[] Customers = {"Alester","Lee","Broad","James"};
setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, Customers));
ListView lv = getListView();
lv.setTextFilterEnabled(true);
答案 0 :(得分:3)
将EditText放在某个位置,例如在listView的顶部,然后添加TextWatcher,如:
TextWatcher filterTextWatcher = new TextWatcher() {
public void afterTextChanged(Editable s) {
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
_myAdapter.getFilter().filter(s);
}
};
_filterText = (EditText) findViewById(R.id.search_box);
_filterText.addTextChangedListener(filterTextWatcher);