0

I have followed this tutorial and have successfully implemented a recylerview with searchview in my app https://github.com/Wrdlbrnft/Searchable-RecyclerView-Demo. However, now instead of having text in my recylerview I have icons representing two states for a user Online and Offline, what I want to do is when the user types in Online in the searchView I only want the Online icon to show up and simiarly when they type Offline I only want the offline icon to show up.

To filter text, as shown in the example I have done this;

if (personStatus.contains(query)) {
             filteredModelList.add(model);

            }

This works perfectly for text based results in my recylerview, however, I want to filter based on icons in the recylerView.

The icon can either be R.drawable.Online or R.drawable.Offline. I have a imageView called icon.

What I have tried so far;

if(query.toLowerCase().equals("online") {

                filteredModelList.add(model.getIcon().getDrawable(R.drawable.online));

            }

This doesn't seem to work, I get a error on getIcon, it says cannot resolve method getIcon. I do have a method getIcon as shown in the example above in the exampleModel class;

what I want to do is;

IF searchView text = "Online" THEN
   Only show recylerview items that contains icon Online

I hope I have explained myself fully, if not please let me know.

Henry
  • 1,042
  • 2
  • 17
  • 47

1 Answers1

0

The approach you are using might be slow when dealing with large data set, because you are doing the search on the main thread. If the searching does not complete in 8ms you are about to experience junk.

Comparison that you are using query.toLowerCase().equals("online") is fine. You need to move that logic inside your adapter that should implement Filterable. You need to toggle that online/offline status in your model, like: setStatus(Status.ONLINE) or setStatus(Status.OFFLINE) so iteration to find all items for particular status is easy, only with using your condition & constraint from the SearchView, i.e query.toLowerCase().equals("online").

Take a look at my answer here. It is more or less I mentioned.

Community
  • 1
  • 1
Nikola Despotoski
  • 49,966
  • 15
  • 119
  • 148