Detect when ListView has reached the bottom - onScroll() or onScrollStateChanged()?
Here's some code for my suggested third approach, which I use in my own projects. I use the adapter's getView
method to detect when the end of the list has been reached.
public View getView(int position, View convertView, ViewGroup parent) {
// handle recycling/creating/initializing view
if(reachedEndOfList(position)) loadMoreData();
return convertView;
}
private boolean reachedEndOfList(int position) {
// can check if close or exactly at the end
return position == getSize() - 1;
}
private void loadMoreData() {
// Perhaps set flag to indicate you're loading and check flag before proceeding with AsyncTask or whatever
}