Skip to content Skip to sidebar Skip to footer

How To Update Query For Firebase Ui Recycler View Adapter?

I am using Firebase UI for displaying data in recyler view from Firestore. Currently I am setting up the query and passing it to the recycler view once in the beginning. Now I want

Solution 1:

You can update the options (including the query) of an existing FirestoreReyclerAdapter adapter by calling its updateOptions method:

val newOptions = FirestoreRecyclerOptions.Builder<ItemModel>()
    .setQuery(newQuery, ItemModel::class.java)
    .setLifecycleOwner(this)
    .build()
adapter.updateOptions(newOptions);

See this branch where the feature was added in July 2019.

Solution 2:

I made this update in my graddle and the updateOptions method became available. make sure in you gradle module app you have at least these versions or higher:

implementation'com.firebaseui:firebase-ui-firestore:6.3.0'
implementation 'com.firebaseui:firebase-ui-storage:6.3.0'

then do this:

val newOptions = FirestoreRecyclerOptions.Builder<ItemModel>()
    .setQuery(newQuery, ItemModel::class.java)
    .setLifecycleOwner(this)
    .build()
adapter.updateOptions(newOptions);

Solution 3:

You will have to do exactly what you are already doing now:

  1. Create a new Query object
  2. Provide it to a new instance of FirestoreRecyclerAdapter
  3. Add the adapter to the recyclerview

You can't replace the query inside an existing adapter - you have to create a whole new adapter. You can reuse the existing RecyclerView or not - it's up to you.

Post a Comment for "How To Update Query For Firebase Ui Recycler View Adapter?"