展开式回收站视图搜索视图不起作用

时间:2018-11-13 12:43:21

标签: android android-recyclerview

这是我的recyclerview可过滤代码的过滤方法。

     @Override
    public Filter getFilter() {
        return new Filter() {
            @Override
            protected FilterResults performFiltering(CharSequence charSequence) {
                String charString = charSequence.toString();
                if (charString.isEmpty()) {
                    mParentItemList = mOriginalList;
                } else {
                    List<ParentListItem> filteredList = new ArrayList<>();
                    for (ParentListItem row : mParentItemList) {

                        // name match condition. this might differ depending on your requirement
                        // here we are looking for name or phone number match
                        for (Object childListItem : row.getChildItemList()) {
                            if (((Help) childListItem).getName().toLowerCase().contains(charString.toLowerCase())) {
                                filteredList.add(row);
                            }
                        }

//                        if (row.getName().toLowerCase().contains(charString.toLowerCase()) || row.getPhone().contains(charSequence)) {
//                            filteredList.add(row);
//                        }
                    }

                    mParentItemList = filteredList;
                }

                FilterResults filterResults = new FilterResults();
                filterResults.values = mParentItemList;
                return filterResults;
            }

            @Override
            protected void publishResults(CharSequence charSequence, FilterResults filterResults) {
                mParentItemList = (ArrayList<ParentListItem>) filterResults.values;
                notifyDataSetChanged();
            }
        };
    }

我正在mParentList变量中正确获取过滤列表,但是当我调用notifydatasetchanged()时recyclerview没有更新,UI也没有更新。

0 个答案:

没有答案