如何在FirestorePagingAdapter中获取项目列表?

时间:2019-08-18 10:55:41

标签: android firebase google-cloud-firestore firebaseui

我正在使用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);
                }
            }

1 个答案:

答案 0 :(得分:0)

  

相当于FirestorePagingAdapter中的onDataChanged()

是BaseChangeEventListener的onDataChanged()方法,其名称与您在问题中提到的名称相同。来自班级中存在的语言:

  

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