How to notify FirestorePagingAdapter?

这一生的挚爱 提交于 2019-12-14 04:10:33

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!