如何通知FirestorePagingAdapter? [英] How to notify FirestorePagingAdapter?

查看:69
本文介绍了如何通知FirestorePagingAdapter?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用FirestorePagingAdapter来显示Firestore中的数据并分页数据.当Firestore更改时,我想用新数据刷新适配器. notifyDataSetChanged()在我想通知数据时不起作用.目前,我正在调用此命令:

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);

}

要通知数据,我要通过查询,然后再次创建我不想要的适配器obj.

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

推荐答案

您不能在Firebase-UI库中使用FireStorePagingAdapter来接收更新,因为它仅用于获取数据而不用于侦听实时更新.在

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();

您也可以通过此 帖子查看我的回答 ,您可以在其中找到有关如何通过将查询游标与limit()方法结合使用来对查询进行分页的示例.我还建议您观看此 视频 更好的理解.

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.

这篇关于如何通知FirestorePagingAdapter?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆