Skip to content Skip to sidebar Skip to footer

RecyclerView List Items Search Using EditText Implementing Filterable Do Not Work

SearchListAdapter.java RecyclerView List Search using EditText implementing filterable do not work. Please check out this code. Here in my case the list is filtered but recyclerVie

Solution 1:

Finally done but using another way, not implementing fiterable.

        @Override
        public void onTextChanged(CharSequence s, int start,
                                  int before, int count) {


            final String query = s.toString().toLowerCase().trim();
            final ArrayList<ChapterListModel> filteredList = new ArrayList<>();

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

                final String text = chapterLists.get(i).getTitle().toLowerCase();
                if (text.contains(query)) {
                    filteredList.add(chapterLists.get(i));
                }
            }

            recyclerView.setLayoutManager(new LinearLayoutManager(SearchActivity.this));
            adapter = new SearchListAdapter(SearchActivity.this, filteredList);
            recyclerView.setAdapter(adapter);
            adapter.notifyDataSetChanged();  // data set changed


        }

Solution 2:

Your onBindViewHolder and getItemCount methods should be using the filteredChapterList. Right now, you are filtering your list, correctly notifying the adapter of the change, but you're always using the original list!

In your constructor, you should also change filteredChapterList = new ArrayList<>(originalChapterList)


Solution 3:

et_serachList.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) {

            final String query = s.toString();
            final ArrayList<data> filteredList = new ArrayList<>();
            if (data_single.size()!=0) {
                for (int i = 0; i < data_single.size(); i++) {
                    final String text = data_single.get(i).getMobile_no();
                    System.out.println("getMobile_number" + text);
                    if (text.contains(query)) {
                        filteredList.add(data_single.get(i));
                    }
                    personAdapter = new DeliverPersonAdapter(getContext(), filteredList);
                    recyclerView.setAdapter(personAdapter);
                    report_order = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
                    recyclerView.setLayoutManager(report_order);
                    personAdapter.notifyDataSetChanged();
                }
            }
        }
        @Override
        public void afterTextChanged(Editable s) {
            //  filter(s.toString());

        }
    });

Post a Comment for "RecyclerView List Items Search Using EditText Implementing Filterable Do Not Work"