字段更改时,FirestorePagingAdapter无法更新Firestore数据吗?

时间:2020-05-22 12:08:03

标签: firebase google-cloud-firestore android-recyclerview

当前,我正在使用FirestoreRecyclerAdapter和FirestoreRecyclerOptions,并且他可以监听数据更新,但是此方法消耗大量数据,因此,我尝试使用FirestorePagingOptions和FirestorePagingAdapter,他可以对数据进行分页并节省了日期,但是,当数据更新时,RecyclerView方法不会发生这种情况,我有adapter.startListening(),但是没有用。

这很好,但是消耗的数据很强大。

public class AnuncioAdapter extends FirestoreRecyclerAdapter<AnuncioPrincipal, AnuncioAdapter.AnuncioHolder> {

    public AnuncioAdapter(FirestoreRecyclerOptions<AnuncioPrincipal> options)
    {
        super(options);
    }

该方法经济可行,但无法更新...

public class AnuncioAdapter extends FirestorePagingAdapter<AnuncioPrincipal, AnuncioAdapter.AnuncioHolder> {

    public AnuncioAdapter(FirestorePagingOptions<AnuncioPrincipal> options)
    {
        super(options);
    }

2 个答案:

答案 0 :(得分:3)

FirebaseUI分页适配器不使用实时侦听器。根据{{​​3}}:

FirestorePagingAdapter通过将文档加载到页面中来将查询绑定到RecyclerView。这样可以节省时间和内存,但是它放弃了FirestoreRecyclerAdapter 努力的实时事件。

因此,您必须选择:您可以具有实时更新,也可以具有分页功能,但是FirebaseUI随附的适配器不能同时具有这两种功能。

答案 1 :(得分:0)

很简单

  1. 你是否在一个方法中简化了 FirestorePagingAdapter,例如 loadAdapter()
  2. 现在执行 Normal Listener 并调用 loadAdapter() 以针对每次更改重新加载。