Skip to content

Instantly share code, notes, and snippets.

@LetItRock
Last active June 9, 2022 03:42
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save LetItRock/42ff283f005f764aeb18 to your computer and use it in GitHub Desktop.
Save LetItRock/42ff283f005f764aeb18 to your computer and use it in GitHub Desktop.
Android RecyclerView detecting end of list
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
}
}
}
}
});
@esQmo
Copy link

esQmo commented May 22, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment