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?
source to share
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();
}
source to share
I think there is a better way to do this. Interface implementation OnScrollListener
. Take a look at this: Infinite Scroll Scroll List
source to share