OnScrollListener in your activity class, and then use the following code:
int currentFirstVisibleItem, currentVisibleItemCount, currentTotalItemCount; public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { this.currentFirstVisibleItem = firstVisibleItem; this.currentVisibleItemCount = visibleItemCount; this.currentTotalItemCount = totalItemCount; } public void onScrollStateChanged(AbsListView view, int scrollState) { this.currentScrollState = scrollState; this.isScrollCompleted(); } private void isScrollCompleted() { if (currentFirstVisibleItem + currentVisibleItemCount >= currentTotalItemCount) { if (this.currentVisibleItemCount > 0 && this.currentScrollState == SCROLL_STATE_IDLE) {
If you use AsyncTask to update your data, you can include the following in your PostExecute() to maintain the scroll position:
list.setAdapter(adapter); list.setSelectionFromTop(currentFirstVisibleItem, 0);
Hope this helps.
source share