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?
Create a filter. The "Sort and filter" menu will open. Type in the search bar to find a value or scroll up on the list to see the values in the column. Tap an item to uncheck it and filter it out. The sheet will update automatically.
A RecyclerView. ViewHolder class which caches views associated with the default Preference layouts. A ViewHolder describes an item view and metadata about its place within the RecyclerView. Adapter implementations should subclass ViewHolder and add fields for caching potentially expensive findViewById results.
setHasFixedSize(true) means the RecyclerView has children (items) that has fixed width and height.
In its simplest form, you just create an array adapter passing it a list of objects (that have a proper toString() method). Then you type some characters to the textbox and by default it will filter the results searching in the beginning of the backing object's toString() result.
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:
Your adapter has to implements Filterable.
How to filter a RecyclerView with a SearchView
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With