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.
@OverridepublicvoidonTextChanged(CharSequence s, int start,
int before, int count) {
finalStringquery= s.toString().toLowerCase().trim();
final ArrayList<ChapterListModel> filteredList = newArrayList<>();
for (inti=0; i < chapterLists.size(); i++) {
finalStringtext= chapterLists.get(i).getTitle().toLowerCase();
if (text.contains(query)) {
filteredList.add(chapterLists.get(i));
}
}
recyclerView.setLayoutManager(newLinearLayoutManager(SearchActivity.this));
adapter = newSearchListAdapter(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) {
finalStringquery= s.toString();
final ArrayList<data> filteredList = newArrayList<>();
if (data_single.size()!=0) {
for (inti=0; i < data_single.size(); i++) {
finalStringtext= data_single.get(i).getMobile_no();
System.out.println("getMobile_number" + text);
if (text.contains(query)) {
filteredList.add(data_single.get(i));
}
personAdapter = newDeliverPersonAdapter(getContext(), filteredList);
recyclerView.setAdapter(personAdapter);
report_order = newLinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
recyclerView.setLayoutManager(report_order);
personAdapter.notifyDataSetChanged();
}
}
}
@OverridepublicvoidafterTextChanged(Editable s) {
// filter(s.toString());
}
});
Post a Comment for "Recyclerview List Items Search Using Edittext Implementing Filterable Do Not Work"