1 min readJan 20, 2020
Sivaraj Rajendran You can achieve the pagination with your nestedScrollView like the below code snippet. Hope it will work for you.
nestedScroll.setOnScrollChangeListener(NestedScrollView.OnScrollChangeListener { v, scrollX, scrollY, oldScrollX, oldScrollY ->
if (v.getChildAt(v.childCount - 1) != null) {
if (scrollY >= v.getChildAt(v.childCount - 1).measuredHeight - v.measuredHeight
&& scrollY > oldScrollY) {
val visibleItemCount = layoutManager?.childCount
val totalItemCount = layoutManager?.itemCount
val firstVisibleItemPosition = layoutManager?.findFirstVisibleItemPosition()
if (visibleItemCount!! + firstVisibleItemPosition!! >= totalItemCount!!) {
if (NetworkUtil.checkInternet()) {
if (page < totalPage) {
page++
//call API
}
} else
NetworkUtil.messageNetworkNotConnected()
}
}
}
})