android - 如何在 FirestorePagingAdapter 中获取项目列表?
问题描述
我正在使用 FirestorePagingAdapter 来显示 Firestore 中的项目。加载数据时调用哪个方法?onDataChanged()
像 FirestoreRecyclerAdapter在加载数据时会覆盖一个方法。
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);
}
}
解决方案
什么相当于 onDataChanged()
FirestorePagingAdapter
是 BaseChangeEventListener 的onDataChanged()方法,它与您在问题中提到的方法同名。从课堂上出现的内容中:
处理特定快照中的所有子事件后触发回调。对于批处理事件很有用,例如在初始加载或大型更新批处理后删除加载指示器。
推荐阅读
- javascript - 显示不正确?
- javascript - 在网站和移动应用程序之间整合数据
- javascript - 我想用不同数组的另一个元素更改数组的元素
- vue.js - 如何更改 v-textarea Vue.js 中的选定文本?
- node.js - 调试库不能与 amqplib (rabbitmq) 一起使用
- python - 如何在 Python 中打印 JSON 数据
- java - 获取和打印字符串数组的简单 java 程序
- curl - 包 httr add_headers。httr::get() 与 cURL
- julia - 跨不同模块的相同类型之间没有签名匹配
- firebase-realtime-database - gRPC - Firestore 如何实现服务器-> 客户端实时流式传输