I'm trying to get filtered recyclerview count because if it is zero I want to show text. But the returned value is old filtered count. How can I solve this?

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

Returning to the old value is not the current value.

In my recyclerview adapter.

@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();
            }
        };
    }

0 Answers