Filtering in my custom adapter not working

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Filtering in my custom adapter not working



I'm trying to add a filter to my recylerview adapter. I'm following this tutorial https://www.androidhive.info/2017/11/android-recyclerview-with-search-filter-functionality/ . But, i'm using edittext. Here is how i set my edittext


<EditText
android:imeOptions="flagNoExtractUi"
android:hint="Search"
android:id="@+id/itemsearch"
android:layout_width="match_parent"
android:layout_height="wrap_content" />



and here is how i setup my search


itemsearch.addTextChangedListener(new TextWatcher()
@Override
public void afterTextChanged(Editable arg0)
String text = itemsearch.getText().toString().toLowerCase(Locale.getDefault());
adapter_order.getFilter().filter(text);
Log.d("TEXT", text);


@Override
public void beforeTextChanged(CharSequence arg0, int arg1,
int arg2, int arg3)


@Override


public void onTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3)

// TODO Auto-generated method stub

);



and here is my filter() inside my adapter


filter()


@Override
public Filter getFilter()

Log.d("GO", "GO FILTER");

return new Filter()
@Override
protected FilterResults performFiltering(CharSequence charSequence)
String charString = charSequence.toString();
Log.d("MYS", charString);
if (charString.isEmpty())
listfilter = list;
else
List<Model_item> filteredList = new ArrayList<>();
for (Model_item row : list)
if (row.getItemName().toLowerCase().contains(charString.toLowerCase())
listfilter = filteredList;


FilterResults filterResults = new FilterResults();
filterResults.values = listfilter;
return filterResults;


@Override
protected void publishResults(CharSequence charSequence, FilterResults filterResults)
listfilter = (ArrayList<Model_item>) filterResults.values;
notifyDataSetChanged();

;



but nothing happen. and my Log.d inside filter() is not showing


Log.d


filter()





you need some custom adapter like: class Adapter extends MatchableArrayAdapter<Model_item> { ... and override its onBind() and matches() methods
– pskink
38 mins ago


class Adapter extends


<Model_item> { ...


onBind()


matches()





@pskink i already have custom adapter. should i create one or ?
– MyNameIs
2 mins ago





you can reinvent the wheel if you want or use this simple adapter instead - try it in your code and see how it works
– pskink
13 secs ago









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard