使用edittext和spinner过滤listview

时间:2018-04-14 01:54:52

标签: android listview filter

我有一个包含数据库信息的列表,这个信息可以通过带有标记的产品系列对其进行过滤,直到这里一切都很好,但我需要设置搜索引擎以使搜索更加迅速(因此我想放置一个过滤的文字

enter image description here

1 个答案:

答案 0 :(得分:1)

此代码可帮助您搜索列表

如果要直接从数据库中搜索循环中的put查询

edPeopleSearch.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, 
                   int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            edPeopleSearch.setCursorVisible(true);
            if (list != null) {
                s = s.toString().toLowerCase();
                final ArrayList<PagePeopleModel> filter_list = new ArrayList<PagePeopleModel>();

                for (int i = 0; i < list.size(); i++) {

                    final String text = list.get(i).getFirst_name().toLowerCase() + list.get(i).getLast_name().toLowerCase();
                    if (text.contains(s)) {

                        filter_list.add(list.get(i));
                    }
                }

                adapter = new PagePeopleAdapter(activity, filter_list);
                resViewPeopleCode.setAdapter(adapter);
                adapter.notifyDataSetChanged();

                if (s.length() > 0) {
                    imgPagePeopleClose.setVisibility(View.VISIBLE);
                } else {
                    imgPagePeopleClose.setVisibility(View.GONE);
                }

            }
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });