Custom Filtering ArrayAdapter in ListView

前端 未结 4 1023
孤独总比滥情好
孤独总比滥情好 2020-12-01 05:18

I am a begginer in Android but I tried to make a custom listview filtering and I it worked somehow. The only problem I have is that the ArrayList that I kept all the values

4条回答
  •  天命终不由人
    2020-12-01 06:13

    They have it covered here: https://www.mysamplecode.com/2012/07/android-listview-custom-layout-filter.html

    You'll need to call clear() on the arrrat adapter to not hit the indexBoundException and add() on every element, since addAll() is valid only since honeycomb.

    @SuppressWarnings("unchecked") @Override protected void publishResults(CharSequence constraint, FilterResults results) {

    countryList = (ArrayList)results.values;
    notifyDataSetChanged();
    clear();
    for(int i = 0, l = countryList.size(); i < l; i++)
     add(countryList.get(i));
    notifyDataSetInvalidated();
    

    }

提交回复
热议问题