IndexOutOfBoundException on filtering SimpleAdapter

前端 未结 2 353
一整个雨季
一整个雨季 2021-01-21 10:05

I sub classed SimpleAdapter to add some extra functionality to it, like changing background color, custom views and filtering. The background thing is working out g

相关标签:
2条回答
  • 2021-01-21 10:44

    No need to add filter and bindView methods, only make sure for getView:

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = super.getView(position, convertView, parent);
    
        if(position%2!=0) {
            v.setBackgroundColor(Color.DKGRAY);
        }
        else {
            v.setBackgroundColor(Color.BLACK);
        }
    
        return v;
    }
    
    0 讨论(0)
  • 2021-01-21 10:54

    Try this code:

    @SuppressWarnings("unchecked")
    @Override
    protected void publishResults(CharSequence constraint, FilterResults results) {
        data.clear();
        data.addAll((List<Map<String, String>>) results.values);
        if (results.count > 0) {
           notifyDataSetChanged();
        } else {
           notifyDataSetInvalidated();
        }
    }
    
    0 讨论(0)
提交回复
热议问题