【问题标题】:How to get item list in FirestorePagingAdapter?如何在 FirestorePagingAdapter 中获取项目列表?
【发布时间】:2019-12-23 21:55:04
【问题描述】:

我正在使用 FirestorePagingAdapter 来显示 Firestore 中的项目。加载数据时调用哪个方法?像 FirestoreRecyclerAdapter 在加载数据时会覆盖一个方法 onDataChanged()

FirestoreRecyclerAdapter adapter = new FirestoreRecyclerAdapter<Chat, ChatHolder>(options) {
    // ...

    @Override
    public void onDataChanged() {
        // Called each time there is a new query snapshot. You may want to use this method
        // to hide a loading spinner or check for the "no documents" state and update your UI.
        // ...
    }

    @Override
    public void onError(FirebaseFirestoreException e) {
        // Called when there is an error getting a query snapshot. You may want to update
        // your UI to display an error message to the user.
        // ...
    }
};

相当于 FirestorePagingAdapter 中的 onDataChanged()。我试过onCurrentListChanged(),但currentList的大小始终为零。

@Override
public void onCurrentListChanged(@Nullable PagedList<DocumentSnapshot> currentList) {

                if(currentList.size()==0){
                    Log.e(TAG, "onCurrentListChanged: no data");
                    emptyBoxAnimation.setVisibility(View.VISIBLE);
                }
            }

【问题讨论】:

    标签: android firebase google-cloud-firestore firebaseui


    【解决方案1】:

    什么相当于FirestorePagingAdapter中的onDataChanged()

    是 BaseChangeEventListener 的 onDataChanged() 方法,与您在问题中提到的名称相同。从类中存在的组件中:

    在处理特定快照中的所有子事件后触发回调。对于批处理事件很有用,例如在初始加载或大批量更新后移除加载指示器。

    【讨论】:

    • 如果我们使用 FirestorePagingAdapter 加载聊天消息,那么它将如何检测新消息到达,目前我正在使用 FirestoreRecyclerAdapter 自动加载新消息但它不能延迟加载数据,所以我们必须使用 FirestorePagingAdapter .您对此有什么解决方案吗?
    • 嗨沙里尔!我可以帮助您了解其他信息吗?如果您认为我的回答对您有所帮助,请考虑通过单击左侧投票箭头下方的复选标记(✔️)来接受它。应将颜色更改为绿色。我会很感激的。谢谢!
    • @Nainal 您应该针对该主题提出一个新的单独问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-01-23
    • 2010-09-26
    • 2023-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多