i extend ListActivity
and bind ListView
in my activity. applied filter to listview. the filter is working fine when use emulater, because i have keyboard of my laptop. but the problem arises when i want to filter data on android because it does not display keyboard to me. code is give below.
String[] Customers = {"Alester","Lee","Broad","James"};
setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, Customers));
ListView lv = getListVie开发者_开发问答w();
lv.setTextFilterEnabled(true);
Put an EditText somewhere, like on top of your listView, then add a TextWatcher like :
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);
精彩评论