How to implement multiple filtering on RecyclerView based android app?
Asked Answered
S

1

8

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

Schizopod answered 22/8, 2016 at 14:41 Comment(3)
for easy filtering use this generic adapterBarabarabarabas
@Barabarabarabas That's an awesome class, but I'm not sure how to use it exactly. Would you mind answering with some code?Nessi
@Nessi pastebin.com/raw/LEena3pMBarabarabarabas
O
2

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

Og answered 22/8, 2016 at 15:23 Comment(1)
Can you give a sample layout?Nessi

© 2022 - 2024 — McMap. All rights reserved.