Skip to content

Instantly share code, notes, and snippets.

@raviyadav4875
Created April 28, 2018 10:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raviyadav4875/218d2433e2389c4fd106b834da2577ab to your computer and use it in GitHub Desktop.
Save raviyadav4875/218d2433e2389c4fd106b834da2577ab to your computer and use it in GitHub Desktop.
addOnScrollListener.java
/**
* For Adding Load more functionality
*
*/
rvMoviesList.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if (dy > 0) {
visibleItemCount = recyclerView.getChildCount();
totalItemCount = linearLayoutManager.getItemCount();
firstVisibleItem = linearLayoutManager.findFirstVisibleItemPosition();
if (loading) {
if (totalItemCount > previousTotal) {
loading = false;
previousTotal = totalItemCount;
}
}
if (!loading && (totalItemCount - visibleItemCount)
<= (firstVisibleItem + visibleThreshold)) {
// End has been reached
Log.i("InfiniteScrollListener", "End reached");
callGetTopRatedMoviesApi();
loading = true;
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment