I implemented a filter class in my application to filter ListView. Now I want to add all items of expressionlist in ListView when the user type in and doesn't match the filter, instead of display ListView in blank.
How can I do this? I need some help.
public void filter(String charText) {
charText = charText.toLowerCase(Locale.getDefault());
expressionlist.clear();
if (charText.length() == 0) {
expressionlist.addAll(arraylist);
} else {
for (Expression wp : arraylist) {
if (wp.getWord().toLowerCase(Locale.getDefault())
.contains(charText)) {
expressionlist.add(wp);
}
}
}
notifyDataSetChanged();
}
}
After you filter by search keyword. You can check the size of result array.
If it is empty, add the data that you want to display then
notifyDataSetChanged