I have a ListView and an EditText. I implement addTextChangedListener on EditText to filter the ListView content.
leftList.setTextFilterEnabled(true);
et_search.addTextChangedListener(filterTextWatcher);
and then the TextWatcher is:
private 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) {
if (watcherAdapter==null) {
return;
}
watcherAdapter.getFilter().filter(s);
Log.e(TAG, "OnTextChange: " + s + " start: " + start +
" before: " + before + " count: " + count + " adapter: " +
watcherAdapter.getCount());
}
};
Condition:
- I have 10 items in
ListView.
Question:
- When I first type the first character, why the
watcherAdapter.getCount()returns10(as initial) inListView instead of the returned filter result count? ThewatcherAdapter.getCount() seems a-click late for the displayed result inListView. - How I achieve to show
"No Result"inListViewwhen there is no match results as I type on theEditText?
The only solution I use at last is to do my custom search filter….Split the words, tokenizes them, and if matched put it on array as adapter to the List. And it works as I want it