问题
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.
回答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.
回答2:
just call com.firebase.ui.firestore.paging.FirestorePagingAdapter#refresh
来源:https://stackoverflow.com/questions/51175650/how-to-notify-firestorepagingadapter