Last active
June 9, 2022 03:42
-
-
Save LetItRock/42ff283f005f764aeb18 to your computer and use it in GitHub Desktop.
Android RecyclerView detecting end of list
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
private boolean loading = true; | |
int pastVisiblesItems, visibleItemCount, totalItemCount; | |
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() | |
{ | |
@Override | |
public void onScrolled(RecyclerView recyclerView, int dx, int dy) | |
{ | |
if(dy > 0) //check for scroll down | |
{ | |
visibleItemCount = mLayoutManager.getChildCount(); | |
totalItemCount = mLayoutManager.getItemCount(); | |
pastVisiblesItems = mLayoutManager.findFirstVisibleItemPosition(); | |
if (loading) | |
{ | |
if ( (visibleItemCount + pastVisiblesItems) >= totalItemCount) | |
{ | |
loading = false; | |
Log.v("...", "Last Item Wow !"); | |
//Do pagination.. i.e. fetch new data | |
} | |
} | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey? How one could detect item at specific position, say position 0? I need something to be able to get the item value when at position 0