masu.mo
masu.mo

Reputation: 793

How to implement multiple filtering on RecyclerView based android app?

Currently, I have developed an Activity to show list of data using RecyclerView with searching feature (as seen at image_1).

I want to add filtering option to the toolbar similar to the filter on the Youtube app (see image_2). Can anyone can give me clues to easily implement it? Both for the UI design and business logic.

Any idea how to implement the filter dialog window (see image_3)? Should I just use AlertDialog or is there any other better options?

image_1 image_2 image_3

Upvotes: 8

Views: 8024

Answers (1)

Thiago Souto
Thiago Souto

Reputation: 771

So, you need to create a options menu that starts a DialogFragment with a custom layout and get the tags filtered by the user in your dialog, then you can use them to filter your recyclerview.

Your adapter should implements Filterable interface!!

You can do it by following theses instructions:

  1. Create a OptionsMenu that starts your DialogFragment. Create a
  2. DialogInterface.OnClickListener to your search button in the dialog
  3. that call your adapter.filter by your tags. Create a
  4. Filter(android.widget.Filter) that receives your tags and then you could filter the data and notify!

Your adapter has to implements Filterable.

How to filter a RecyclerView with a SearchView

Upvotes: 2

Related Questions