0

I am using FirestorePagingAdapter for showing data from Firestore and paginate the data. I want to refresh the adapter with new data when Firestore changes . notifyDataSetChanged() is not working when ever I want to notify data .currently I am calling this :

 public void setPaging(Query query) {
    FirestorePagingOptions<AddFabricModel> options = new FirestorePagingOptions.Builder<AddFabricModel>()
            .setLifecycleOwner(this)
            .setQuery(query, config, AddFabricModel.class)
            .build();
    adapter=new AllFabricsAdapter(context,options,this);
    rvAllFabrics.setAdapter(adapter);

}

To notify the data I am passing the query then creating the adapter obj again which i dont want.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Adarsh Binjola
  • 216
  • 2
  • 10

2 Answers2

1

You cannot use FireStorePagingAdapter in the Firebase-UI library to receive updates because is designed only to get data and not to listen for realtime updates. Inside the FirestorePagingAdapter class, there is no notifyDataSetChanged() method so to solve this, you need to start listening for changes using:

adapter.startListening();

You can also take a look at my answer from this post where you can find an example on how to paginate queries by combining query cursors with the limit() method. I also recommend you take a look at this video for a better understanding.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • Hey Alex, If I want to build a chat UI and I also want to let the users see old messages. Therefore, if I go with FirestorePagingOptions I have to load all the data or I can limit it. Is there a way to update real-time and also load the old data step by step :) using firestoreUI or any recommend method? :) – Isuru Bandara Oct 08 '20 at 12:38
  • 1
    @IsuruBandara I think you might be interested in this [article](https://medium.com/firebase-tips-tricks/how-to-create-a-clean-firestore-pagination-with-real-time-updates-ce05a87bb902). – Alex Mamo Oct 08 '20 at 14:27
  • 1
    That's what I wanted. Thank you for making useful articles on Medium :) – Isuru Bandara Oct 08 '20 at 15:34
0

just call com.firebase.ui.firestore.paging.FirestorePagingAdapter#refresh

Mattatyahu
  • 71
  • 4