Android - How To Filter A Listview On Multiple Values?
I want to filter a listView on song title and artist. Currently I have a working filter on song title. But I can't figure out how to filter on song title and artist at the same mom
Solution 1:
Just add the below method in your custom adapter.
publicvoidfilter(String charText) {
charText = charText.toLowerCase(Locale.getDefault());
arrData.clear();
if (charText.length() == 0) {
arrData.addAll(arrDataFilter);
} else {
for (ContactMyDataClass cMDC : arrDataFilter) {
if(cMDC.getContactName().toLowerCase(Locale.getDefault()).contains(charText)){
arrData.add(cMDC);
}
}
}
notifyDataSetChanged();
}
and than
@OverridepublicvoidonTextChanged(CharSequence s, int start, int before, int count) {
adapterContactList.filter(s.toString());
}
Post a Comment for "Android - How To Filter A Listview On Multiple Values?"