Android – listView slide loaded next page data SCROLL setting

Android-ListView slides to load new data

I encountered a problem, the slide load function in the past was very poor, and I don’t know the reason.

After trying for a long time, I finally tried it out.

I think this method is more in line with the user experience.

It will not feel visually bounced, but it will load straight and smoothly.

The following is the onScrollListener I set

private OnScrollListener scrollListener = new OnScrollListener() {

@Override
public void onScroll(AbsListView view, int firstItem, int visible, int total) {
scrollCount = visible + firstItem;
}

// 0. Stop scrolling 1. Scrolling
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
if( scrollState == SCROLL_STATE_IDLE) {
mPosition = view.getFirstVisiblePosition();
View v = view.getChildAt(0);
mTop = (v == null)? 0: v.getTop();

if( scrollCount >= perPage * page && pageCount >= page) {
page++;
loadNextPage();
}
}
}
};

Wait for loading, and after the data is collected, reset the position as follows

listView.setSelectionFromTop(mPosition, mTop);

< p>

Original text: Large column Android-ListView slide to load the next page data Scroll settings

Leave a Comment

Your email address will not be published.