IndexOutOfBoundException on filtering SimpleAdapter

冷暖自知 提交于 2019-12-02 05:59:27
Николай Привалов

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();
    }
}
IvNieto

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;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!