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.