Sep 1, 2018 · 1 min read
setOnScrollListener has been deprecated and changed to addOnScrollListener. Doing the logic in onScrolled seems wrong to me for some reason. Doing it in onScrollStateChanged, and detecting the idle state to do the checks eg this…
int visibleItemCount = layoutManager.getChildCount();
int totalItemCount = layoutManager.getItemCount();
int firstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition();
if (!isLoading && !isLastPage) {
if ((visibleItemCount + firstVisibleItemPosition) >= totalItemCount
&& firstVisibleItemPosition >= 0
&& totalItemCount >= PAGE_SIZE) {
loadMoreItems();
}
}… would make more sense.
