我正在尝试过滤recyclerview计数,因为如果它为零,我想显示文本。但是返回的值是旧的过滤计数。 我该怎么解决?
Listener
Subscription editTextSub =
(Subscription)RxTextView.textChanges(editText)
.skip(1)
.debounce(1000, TimeUnit.MILLISECONDS)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(s -> {
mAdapter.getFilter().filter(editText.getText());
System.out.println("x " + mAdapter.getItemCount());
});
Item = 2 but return = 2000
Item = 120 but return = 2
Item = 46 but return = 120
返回旧值不是当前值。
在我的recyclerview适配器中。
@Override
public int getItemCount() {
return contactListFiltered.size();
}
@Override
public Filter getFilter() {
return new Filter() {
@Override
protected FilterResults performFiltering(CharSequence charSequence) {
String charString = charSequence.toString();
if (charString.isEmpty()) {
contactListFiltered = directoryListModel;
} else {
List<DirectoryModel> filteredList = new ArrayList<>();
for (DirectoryModel row : directoryListModel) {
if(searchParameter == 0){
if (row.x.toLowerCase().contains(charString.toLowerCase())){ filteredList.add(row); }
}else if(searchParameter == 1){
if (row.y.toLowerCase().contains(charString.toLowerCase())){ filteredList.add(row); }
}else if(searchParameter == 2){
if (row.z.toLowerCase().contains(charString.toLowerCase())){ filteredList.add(row); }
}
}
contactListFiltered = filteredList;
}
FilterResults filterResults = new FilterResults();
filterResults.values = contactListFiltered;
return filterResults;
}
@Override
protected void publishResults(CharSequence charSequence, FilterResults filterResults) {
contactListFiltered = (ArrayList<DirectoryModel>) filterResults.values;
notifyDataSetChanged();
}
};
}