这是我的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也没有更新。