0

创建一个数组列表

public ArrayList<HashMap<String,Object>> list=new ArrayList<HashMap<String,Object>>();

添加 simpleAddapter 以显示 4 字段现在我想在列表中搜索一个项目,所以我使用了

search.addTextChangedListener(new TextWatcher() {

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
        ((SimpleAdapter)getListAdapter()).getFilter().filter(s); 
                        }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count,
            int after) {
        // TODO Auto-generated method stub

    }

    @Override
    public void afterTextChanged(Editable s) {
        // TODO Auto-generated method stub

    }
});

它正确过滤listView,但是当我尝试访问listview项目时,它不会返回正确的位置,即如果两个项目在文件后显示,则位置与旧列表项相同..那么如何从onListItemClick获取正确的数据? ?

4

3 回答 3

0

将过滤后的 ArrayList 发送到自定义适配器,在其构造函数中对其进行初始化,然后在适配器的 getItem() 函数中使用 ArrayList,例如:

public Object getItem(int position) {
    return list.get(position).get("key");
}
于 2013-05-25T06:27:25.210 回答
0

这对我有用

mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, final View view,
                                    int position, long id) {

                //abrirActividadDetallada(position, id);
                Object MyObject=(Object) parent.getAdapter().getItem(position);
                CustomMethod(MyObject);
            }
        });
于 2015-03-06T18:12:08.707 回答
0
    #get actual position of list after filter listview
    1.
      @Override// use in adapter
        public long getItemId(int position) {
            return list.get(position).getID();
        }
    list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Log.d(“actual position”,String.valueof((int)id))
                }enter code here
            });
于 2017-02-06T12:17:07.670 回答