Searchview with customlistview和ArrayList <hashmap <string,string =“”>&gt;

时间:2017-04-04 06:35:58

标签: android searchview

你好我已经在我的android项目中实现了自定义列表视图,现在我想在listview上实现搜索功能,我怎么能实现...

我没有得到如何搜索listview和更新listview相应的查询相同的arraylist

1 个答案:

答案 0 :(得分:0)

使用Model类的ArrayList而不是Hashmap。

    private class DataModel{
    String userName;
    String emailAdd;
    int age;
    }

    public class DataAdapter extends BaseAdapter {


        ArrayList<DataModel> data;
ArrayList<DataModel> filterData;
        LayoutInflater lat = getLayoutInflater();
        private Context context;
        Typeface custom_font;

        public DataAdapter(Context context, ArrayList<HashMap<String, String>> arraylist) {
            this.context = context;
            data = arraylist;
            Log.d("DATA", data.toString());
           filterData = new ArrayList(data.size());

        }

public void filter(String searchQuery){
for(DataModel model : filterData){
if(model.userName.equals(searchQuery)){
 filterData.add(model);
}
}
notifidatasetchanged();
}

        @Override
        public int getCount() {
                return filterData.size();
        }

        @Override
        public Object getItem(int position) {
            return data.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            convertView = lat.inflate(R.layout.inflate_chooselab, null);
    }
    }

希望你明白,我没有尝试过代码,发布你的查询,如果有的话。