Skip to content

Instantly share code, notes, and snippets.

@EfeBudak
Created May 30, 2017 08:31
Show Gist options
  • Save EfeBudak/a099952e9890dfe5c2cb2c2c6c2d6291 to your computer and use it in GitHub Desktop.
Save EfeBudak/a099952e9890dfe5c2cb2c2c6c2d6291 to your computer and use it in GitHub Desktop.
Android Pagination with MVP
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
int visibleItemCount = recyclerView.getLayoutManager().getChildCount();
int totalItemCount = recyclerView.getLayoutManager().getItemCount();
int firstVisibleItemPosition = ((LinearLayoutManager) recyclerView.getLayoutManager()).findFirstVisibleItemPosition();
if (!mSwipeRefreshLayout.isRefreshing() && !mEndOfList) {
if ((visibleItemCount + firstVisibleItemPosition) >= totalItemCount - Constants.PAGINATION_MARGIN
&& firstVisibleItemPosition >= 0
&& totalItemCount >= Constants.PAGE_SIZE) {
mPresenter.onLoadNextPage();
}
}
}
});
@vincent-paing
Copy link

vincent-paing commented Oct 26, 2017

What is Constants.PAGE_SIZE here?

@EfeBudak
Copy link
Author

EfeBudak commented Apr 2, 2018

It depends on the number of items that you want to display. 30 - 40...

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