【问题标题】:probleme with Firebase Android paginationFirebase Android分页问题
【发布时间】: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-database pagination,你会发现这个话题之前已经被讨论过很多次了。我建议阅读其中一些答案。
  • 你能用这个方法给我一个建议吗

标签: android firebase firebase-realtime-database android-recyclerview


【解决方案1】:

when you fetch data at a location in your database, you also retrieve all of its child nodes.

(因为您阅读“帖子”)

所以如果你提前记录你的帖子密钥,否则你会下载数据

这样您就可以新建一个目录来储存您的帖子密钥

【讨论】:

  • 我有一个问题,我收到了 5000 个帖子并且变得很重,使应用程序变慢我想知道如何将帖子 10 加载到 10 等等...我是初次登台者,请问如何分页在带有 Firebase 数据库的回收站视图中
猜你喜欢
  • 1970-01-01
  • 2016-10-09
  • 2022-10-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-10-07
  • 2013-01-03
  • 2011-10-26
相关资源
最近更新 更多