0

I Have a huge set of data on Firebase Database, and I want to create a Pagination Functionality for the App. I use try many pagination code but cannot to solve the problem.

recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);

            if (!recyclerView.canScrollVertically(1) && newState==RecyclerView.SCROLL_STATE_IDLE) {
                 mCurrenPage++;
                 loadPost();

            }
        }
    });



private void loadPost() {

    DatabaseReference ref = FirebaseDatabase.getInstance().getReference("Posts");
    Query q = ref.limitToLast(mCurrenPage * TOTAL_ITEMS_TO_LOAD);
    q.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            pg.setVisibility(View.GONE);
            postList.clear();
            for (DataSnapshot ds : dataSnapshot.getChildren()) {
                ModelPost modelPost = ds.getValue(ModelPost.class);

                postList.add(modelPost);
                adapterPost = new AdapterPost(getActivity(), postList);
                recyclerView.setAdapter(adapterPost);
                adapterPost.notifyDataSetChanged();
            }
        }

        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {

        }
    });
}

am using firebase real time database.

  • Maybe this [answer](https://stackoverflow.com/questions/73705896/reading-some-of-data-not-all-from-a-firebase-database-node) will help. – Alex Mamo Sep 23 '22 at 07:44
  • I already tried this but not solve my problem because it's Firestore solution but my code is Firebase real-time database – Naveed Abbas Sep 23 '22 at 10:16

0 Answers0