ListView / ListAdapter Subcategory

I am trying to implement paging in a custom ListAdapter. Right now I'm just making a request to the next page when the last item in the ListView becomes visible, checking getView()

if position

there is a >=

size ListAdapter.getCount()

.

This works great, but I'm wondering if there is a better way (or another way) that will only make the request after the last item in the list is actually visible to the user. Does anyone know the way?

+2


source to share


3 answers


I do it in much the same way:



public static final int SCROLLING_OFFSET = 5;
// ...
private final ArrayList<T> items = new ArrayList<T>();
// ...
if (SCROLLING_OFFSET == items.size() - position) {
    if (hasNextPage()) {
        addNextPage();
    }
}

private boolean hasNextPage() {
    // basically calculates whether the last 2 pages contained the same # of items
}

private void addNextPage() {
    // show spinner
    // fetch next page in a background thread
    // add to items
    notifyDataSetChanged();
}

      

+4


source


I think there is a better way to do this. Interface implementation OnScrollListener

. Take a look at this: Infinite Scroll Scroll List



+2


source


Try to remove the check entirely. In my experience, getView () is only called when the entry is about to appear on the screen.

0


source







All Articles