Pagination not work for the RecyclerView within NestedScrollView

Jatin picture Jatin · Oct 9, 2017 · Viewed 10.8k times · Source

How to implement pagination of recyclerview that is within NestedScrollView?

Answer

Vishva Dave picture Vishva Dave · Oct 9, 2017

Follow this steps :

1. Set nested scrolling enabled false of recycler view.

recyclerView.setNestedScrollingEnabled(false);

2. Add scroll listner to nested scrollview.

 mScrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
           @Override
           public void onScrollChanged()
           {
                    View view = (View)mScrollView.getChildAt(mScrollView.getChildCount() - 1);

                    int diff = (view.getBottom() - (mScrollView.getHeight() + mScrollView
                                    .getScrollY()));

                    if (diff == 0) {
                       // your pagination code
                    }
           }
  });