Created
July 7, 2020 18:08
-
-
Save plsankar/65fd0be53725d7f44b7f301a546a9474 to your computer and use it in GitHub Desktop.
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
public abstract class LoadMoreListener extends RecyclerView.OnScrollListener { | |
private static final int ITEMS_PER_PAGE = 10; | |
private boolean loading = false; | |
private int page = 1; | |
@Override | |
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { | |
super.onScrolled(recyclerView, dx, dy); | |
if (!recyclerView.canScrollVertically(1) | |
&& !loading | |
&& recyclerView.getAdapter() != null | |
&& recyclerView.getAdapter().getItemCount() >= ITEMS_PER_PAGE) { | |
page = page + 1; | |
loading = true; | |
onLoadMore(page); | |
} | |
} | |
public void setLoading(boolean loading) { | |
this.loading = loading; | |
} | |
public void reset() { | |
loading = false; | |
page = 1; | |
} | |
public abstract void onLoadMore(int page); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment