Skip to content

Instantly share code, notes, and snippets.

@yusuphwickama
Last active December 5, 2018 08:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yusuphwickama/ad25e7aaa651b137aae617d609219869 to your computer and use it in GitHub Desktop.
Save yusuphwickama/ad25e7aaa651b137aae617d609219869 to your computer and use it in GitHub Desktop.
Load more items on a list view when scrolling to the bottom.
boolean isLoading = false;
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView absListView, int scrollState) {
if (listAdapter != null &&
scrollState == SCROLL_STATE_IDLE &&
listView.getLastVisiblePosition() == (listView.getCount() - 1) &&
!isLoading && (listAdapter.getCount() != itemsProvider.getTotal())) {
isLoading = true;
// Get more items and add them to the adapter
isLoading = false;
}
}
@Override
public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment