1

img_post_db

I'm looking for a way to implement a simple recycler view scrolling in my Firebase app, but I am not getting any way out how to implement this. I have already tried 2-3 tutorials and documentation available on the Internet, but didn't the required result.

In my app I want scrolling like at starting first 10 list items load then each time on scrolling next 10 or 20 items will load until the last item appears at the bottom of the list.

So I tried retrieving first 10 items the following way :

private void readsposts(){    
    DatabaseReference reference = FirebaseDatabase.getInstance().getReference();
    reference.keepSynced(true);

    reference.child("Posts")
            .limitToLast(10)
            .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);
                            }
                        }

                        postAdapter.notifyDataSetChanged();
                    }
                }

                @Override public void onCancelled(DatabaseError databaseError) {

                }
            });
}

In the above code, as you can see I am generating Log to check if data is fetched from the firebase, but I got no output Android monitor. I have no idea how can I implement Firebase Scrolling in my Recycler view. I think this is a common problem for those who implement infinite-scroll in recycler view/ list view.

Could you please help me implementing this feature?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • If you consider at some point in time to try using [Cloud Firestore](https://firebase.google.com/docs/firestore/), **[this](https://stackoverflow.com/questions/50741958/how-to-paginate-firestore-with-android)** is a recommended way in which you can paginate queries by combining query cursors with the limit() method. I also recommend you take a look at this **[video](https://www.youtube.com/watch?v=KdgKvLll07s)** for a better understanding. – Alex Mamo Dec 31 '19 at 12:07
  • @Lucas where you able to resolve the issue, if so can you please share? I have the same issue. I implemented the new SwiftUI List in my app, and I would like for the items to to be loaded at 10 at a time. – Learn2Code Dec 03 '20 at 15:13

0 Answers0