Skip to content
Advertisement

How to filter data in FirebaseRecyclerOptions by spinner?

I’m using Firebase Database to show data in RecyclerView. Now I want to add a filter option by using an Android spinner. When I try to use different queries code doesn’t work. How can I use the spinner to show data for only 1 query and refresh this by changing the spinner item? This code now works without a spinner click item.

JavaScript

Spinner click item, when the position is 0 it should show all data

JavaScript

Advertisement

Answer

When the user selects an option in the spinner, after you create the new query for the selected option, you’ll need to update the adapter to use that new query.

You do that by creating a new FirebaseRecyclerOptions object with the new query, and then set that on the adapter by calling its updateOptions.

So something like this in your onItemSelected:

JavaScript

There mAdapter is whatever the FirebaseRecyclerAdapter is that you originally also passed your options to.

Advertisement