Created
April 28, 2018 10:26
-
-
Save raviyadav4875/218d2433e2389c4fd106b834da2577ab to your computer and use it in GitHub Desktop.
addOnScrollListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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