Skip to content

Instantly share code, notes, and snippets.

@yava555
Created March 30, 2013 14:09
Show Gist options
  • Save yava555/5276820 to your computer and use it in GitHub Desktop.
Save yava555/5276820 to your computer and use it in GitHub Desktop.
[Android][ListView]Scroll Loading
public class EndlessScrollListener implements OnScrollListener {
//只剩2个未显示时加载
private int visibleThreshold = 2;
private int previousTotal = 0;
private boolean loading = true;
public EndlessScrollListener() {
}
public EndlessScrollListener(int visibleThreshold) {
this.visibleThreshold = visibleThreshold;
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
if (loading) {
if (totalItemCount > previousTotal) {
loading = false;
previousTotal = totalItemCount;
}
}
if (!loading && (totalItemCount - visibleItemCount) <= (firstVisibleItem + visibleThreshold)) {
// I load the next page of gigs using a background task,
// but you can call any function here.
loadMore();
loading = true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment