Created
February 29, 2020 17:40
-
-
Save lawloretienne/fc702f01cb0491ecb0f8a8d315755329 to your computer and use it in GitHub Desktop.
RecyclerViewOnScrollListener
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 RecyclerView.OnScrollListener recyclerViewOnScrollListener = new RecyclerView.OnScrollListener() { | |
@Override | |
public void onScrollStateChanged(RecyclerView recyclerView, int newState) { | |
super.onScrollStateChanged(recyclerView, newState); | |
} | |
@Override | |
public void onScrolled(RecyclerView recyclerView, int dx, int dy) { | |
super.onScrolled(recyclerView, dx, dy); | |
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(); | |
} | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment