0

need to implement a search feature based on an EditText to my RecyclerView. The list must be filtered while typing. I have an edittext and a Rexyclerview I want Recyclerview filter with edittext. I searched a lot on google and found some examples but none worked for me here's my code. I need to clear the list before adding the results

My search feature is filtering but showing same data

 public void filter(String s) {
            String text;
              text = s.toString().toLo`enter code here`werCase();
            text = text.toLowerCase().trim();


            // text = s.toLowerCase(Locale.getDefault());
            mDisplayedValues = new ArrayList<SelectedAthleteDEtail>();
            mDisplayedValues.clear();
            if (text.length() == 0) {
                 mDisplayedValues = AthleteData;
               // mDisplayedValues.addAll(AthleteData);
                BoardRecyclerData.setAdapter(adapter);
                notifyDataSetChanged();
            } else {
                mDisplayedValues.clear();
                notifyDataSetChanged();
                for (SelectedAthleteDEtail cs : AthleteData) {
                         if (cs.getFirstName().toLowerCase().contains(text)) {
                          mDisplayedValues.add(cs);
                             Log.d(TAG, "filterab: "+cs.getFirstName());
                             Log.d(TAG, "filterxyz: "+mDisplayedValues);
                        }
                    }
                }
                BoardRecyclerData.setAdapter(adapter);
                //notifyDataSetChanged();
            }
    }
piet.t
  • 11,718
  • 21
  • 43
  • 52
Sush
  • 11
  • 1
  • Possible Duplicate https://stackoverflow.com/questions/40754174/android-implementing-search-filter-to-a-recyclerview – Xay Jul 12 '19 at 11:22
  • Why you call BoardRecyclerData.setAdapter(adapter);? it call again and again. Did you publish filtered result? I find that in your filter has no return type – Tariqul Islam Jul 12 '19 at 11:29

1 Answers1

0

I think SearchView is what You need.

There is a nice tut.

MarkWalczak
  • 1,532
  • 3
  • 16
  • 24