Custom filtering for Custom ArrayAdapter in ListView

前端 未结 4 2138
小鲜肉
小鲜肉 2021-01-16 03:58

i write a own ArrayAdapter like this one:

public class PoiListAdapter extends ArrayAdapter implements Filterable {

    private Context context;
          


        
4条回答
  •  庸人自扰
    2021-01-16 04:21

    The for-each loop use an Iterator internally, and you can not add nothing to your collection while you are iterating (that's why of the exception). Try creating a new instance of the ArrayList and interate upon it

    @SuppressWarnings("unchecked")
    @Override
    protected void publishResults(CharSequence constraint, FilterResults results) {
        ArrayList fitems = new ArrayList((ArrayList) results.values);
        poiListAdapter.clear();
        for (Poi p : fitems) {
            poiListAdapter.addValuesPoi(p);
            poiListAdapter.notifyDataSetChanged();
        }
    }
    

    the for-each is something like:

    for(Iterator i = fitms.iterator(); i.hasNext(); ) {
      Poi item = i.next();    
    }
    

    Problem 2:

    The List is empty at start probably because the dataset you submit is empty

提交回复
热议问题