To achieve endless scrolling for recycler view which is under NestedScrollView, you can use "NestedScrollView.OnScrollChangeListener"
nestedScrollView.setOnScrollChangeListener((NestedScrollView.OnScrollChangeListener) (v, scrollX, scrollY, oldScrollX, oldScrollY) -> {
if(v.getChildAt(v.getChildCount() - 1) != null) {
if ((scrollY >= (v.getChildAt(v.getChildCount() - 1).getMeasuredHeight() - v.getMeasuredHeight())) &&
scrollY > oldScrollY) {
//code to fetch more data for endless scrolling
}
}
});
Here v.getChildCount() -1
should give you the recycler view for which you be implementing endless scrolling.
Also scrollY > oldScrollY
confirms that the page is being scrolled down.
Reference: NestedScrollView.OnScrollChangeListener
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…