I have list view and its adapter stored as global variables. I am not creating my list by extending ListActivity. My code is as follows:
public void onCreate(Bundle...) {
mListView = (ListView) findViewById(R.id.listview1);
//setting my custom array adapter...works fine.
//also my custom adapter implements Filterable interface
mListView.setAdapter(...)
mListView.setTextFilterEnabled(true);
//My edit text where I enter my query
mSearchEditText = (EditText) findViewById(R.id.searchEditText);
mSearchEditText.addTextChangedLIstener(myListener);
}
private TextWatcher myListener = new TextWatcher () {
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (s == null || s.length() == 0) {
mListView.clearTextFilter();
}
else {
mListView.setFilterText(s.toString());
}
}
...
...
}
My problem is when I enter my string in edit text, it gives me correct no of available search items (only number) in my list but not the items itself.
For example if my list has items aa, bb, cc, dd, ff, ee, ee
So if I search for ee, my result will be aa, bb and not the ee, ee. And if I search cc, my filter list will show aa only.
Can anyone help me on this?
I have a working example, try this:
The adapter must
implements FilterableAnd the filter class:
You can check this post for more info:
Filter expandableList
Filter ListView