【发布时间】:2019-12-13 19:25:41
【问题描述】:
我正在构建一个应用程序,它将显示存储在 firebase 上的帖子。帖子列表需要分页,一次获取最近的 10 个帖子。
这是加载帖子的方法:
private void readsposts(){
DatabaseReference reference = FirebaseDatabase.getInstance().getReference("Posts");
reference.keepSynced(true);
reference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
postList.clear();
for(DataSnapshot snapshot:dataSnapshot.getChildren()){
Post post = snapshot.getValue(Post.class);
for(String id:followingList){
if(post.getPublisher()!=null && post.getPublisher().equals(id)){
postList.add(post);
indication.stopShimmer();
indication.setVisibility(View.GONE);
}
}
if(post.getPublisher()!=null && post.getPublisher().equals(firebaseUser.getUid())){
postList.add(post);
//stop shimmer
indication.setVisibility(View.GONE);
indication.stopShimmer();
}
}
postAdapter.notifyDataSetChanged();
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
但上面的代码检索的是整个帖子列表,而不是有限的帖子。分页如何实现?
【问题讨论】:
-
如果你搜索
firebase-realtime-databasepagination,你会发现这个话题之前已经被讨论过很多次了。我建议阅读其中一些答案。 -
你能用这个方法给我一个建议吗
标签: android firebase firebase-realtime-database android-recyclerview