Tuesday, October 2, 2012

Android - How to detect end of scroll inside List View

Step 1: Set the scroll listener of the list view like below.


list.setOnScrollListener(new OnScrollListener() {});

Step 2: Override the onScroll function and copy/paste the following code

@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {

if (list.getLastVisiblePosition() == list.getAdapter().getCount() - 1
&& list.getChildAt(list.getChildCount() - 1).getBottom() <= list.getHeight()) {
//scroll end reached
//Write your code here
}
}