1

I have a recyclerview which initially fetching last 10 posts. I want a process where when the recyclerview reaches bottom after scrolling it again fetches next 10 posts and so on. I have used gridlayoutmanager for the recyclerview.

My code is:

 Query query = mDatabase.orderByChild("UserId").equalTo(userId).limitToLast(10);


        FirebaseRecyclerAdapter<HomeBlog, BlogViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<HomeBlog, BlogViewHolder>(

                HomeBlog.class,
                R.layout.profile_row,
                BlogViewHolder.class,
                query


        )
        {
            @Override
            protected void populateViewHolder(BlogViewHolder viewHolder, HomeBlog model, int position) {

                final String post_key = getRef(position).getKey();

                //final String postPosition = String.valueOf(position);

                viewHolder.setImage(post_key);


            }
        };

        mBlogList.setAdapter(firebaseRecyclerAdapter);

//mBloglist is the recyclerview

Now I may put the above code in a method and call it from onStart in the beginning and then call it everytime (with some modification) when the recyclerview reaches bottom (with showing a progressbar perhaps)

I guess at first I need some scrolllistener to detect when recyclerview reaches bottom, and then when it does, fetch more data. But I cant seem to do it. Any help will be appreciated.

Zubayr
  • 457
  • 4
  • 18
  • That is a **very** old version of Firebase-UI library. Consider updating it. Beside that, I cannot see in your code something related to pagination. Where are you stuck? – Alex Mamo Aug 11 '19 at 11:05
  • I have used the recyclerview onscrolllistener and tried to recall this particular method again with increasing the value of `limittolast` . But it didnt work. Is there any suggestion that you can give regarding how to proceed (maybe any useful link). And will it be simplier if I move to firestore instead? – Zubayr Aug 11 '19 at 13:53
  • 1
    Yes it might be simpler. So if you consider at some point 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 better understanding. – Alex Mamo Aug 11 '19 at 14:09
  • Thanks. That was really helpful – Zubayr Aug 11 '19 at 15:53

0 Answers0