Home » Java » Firebase database pagination scrolling action

Firebase database pagination scrolling action

Posted by: admin September 21, 2018 Leave a comment


I’m following the tutorial:

I was trying to achieve pagination, Here is what i have modified:

Query query = databaseRef.limitToLast(50);
FirebaseRecyclerOptions<FriendlyMessage> options =
            new FirebaseRecyclerOptions.Builder<FriendlyMessage>()
                    .setQuery(query, parser)

Here is the scrolling code as tutorial as default:

RecyclerView.AdapterDataObserver() {
   public void onItemRangeInserted(int positionStart, int itemCount) {
       super.onItemRangeInserted(positionStart, itemCount);
       int friendlyMessageCount = mFirebaseAdapter.getItemCount();
       int lastVisiblePosition =
       // If the recycler view is initially being loaded or the 
       // user is at the bottom of the list, scroll to the bottom 
       // of the list to show the newly added message.
       if (lastVisiblePosition == -1 ||
               (positionStart >= (friendlyMessageCount - 1) &&
                       lastVisiblePosition == (positionStart - 1))) {


Now the screen shows only 50 messages.

But it don’t scroll to the bottom when new messages coming.It works fine before using query.

I want to know where should I start to modified.

Thank you.