Skip to content

Instantly share code, notes, and snippets.

@ueno-yuhei
Last active November 5, 2016 09:17
Show Gist options
  • Save ueno-yuhei/46b5a717b0f9a28021b1d5bbf5732b08 to your computer and use it in GitHub Desktop.
Save ueno-yuhei/46b5a717b0f9a28021b1d5bbf5732b08 to your computer and use it in GitHub Desktop.
RecyclerViewで一番下まできた時の判定
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
int totalCount = recyclerView.getAdapter().getItemCount(); //合計のアイテム数
int childCount = recyclerView.getChildCount(); // RecyclerViewに表示されてるアイテム数
RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
if (layoutManager instanceof GridLayoutManager) { // GridLayoutManager
GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
int firstPosition = gridLayoutManager.findFirstVisibleItemPosition(); // RecyclerViewに表示されている一番上のアイテムポジション
if (totalCount == childCount + firstPosition) {
// ページング処理
// GridLayoutManagerを指定している時のページング処理
}
} else if (layoutManager instanceof LinearLayoutManager) { // LinearLayoutManager
LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager;
int firstPosition = linearLayoutManager.findFirstVisibleItemPosition(); // RecyclerViewの一番上に表示されているアイテムのポジション
if (totalCount == childCount + firstPosition) {
// ページング処理
// LinearLayoutManagerを指定している時のページング処理
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment