【发布时间】:2023-03-05 07:56:01
【问题描述】:
我有这个 Cloud Firestore 数据库 并使用它来访问它:
CollectionReference robDetails = db.collection("ROBOTS").document(RobotA).collection(RobotB);
每个“Connections”都包含两个带值的字段(ConnectionType & ConnectionTime)。
我想加载 Connections 按 ConnectionTime 排序(底部最新的,如下图所示),但只想显示 3 个最后的连接,当用户向上滚动时,在前一个之上再显示 3 个在 SwipeRefreshLayout 的帮助下:
我目前要像上图一样加载所有连接的代码是:
private void loadConnections() {
CollectionReference loadConnect = db.collection("ROBOTS").document(RobotA).collection(RobotB);
loadConnections.orderBy("connectionTime", Query.Direction.ASCENDING).addSnapshotListener(new EventListener<QuerySnapshot>() {
@Override
public void onEvent(@Nullable QuerySnapshot queryDocumentSnapshots, @Nullable FirebaseFirestoreException e) {
for (DocumentChange documentChange : queryDocumentSnapshots.getDocumentChanges()) {
Connections connection = documentChange.getDocument().toObject(Connections.class);
mConnectionsList.add(connection);
mAdapter.notifyDataSetChanged();
conRecyclerView.scrollToPosition(mConnectionsList.size() - 1);
conSwipeRefresh.setRefreshing(false);
}
}
});
}
TL;DR: 我想先在我的 RecyclerView 中加载 Part1,当用户向上滚动加载 Part2 时,当用户向上滚动加载 Part3... 时使用 SwipeRefreshLayout。
【问题讨论】:
标签: java android android-recyclerview pagination google-cloud-firestore