我正在尝试在自定义的ListAdapter中实现分页。现在,当ListView中的最后一项可见时,我正在请求下一页,方法是检查getView(),如果position的大小等于ListAdapter.getCount()的大小。
它工作得很好,但我想知道是否有更好的方法(或不同的方法),只在列表中的最后一项对用户可见时才发出请求。有谁知道有什么办法吗?
发布于 2010-04-12 05:34:18
我也是这样做的:
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();
}发布于 2011-05-07 01:24:44
我认为有一种更好的方法。实现OnScrollListener接口。看看这个:Endless Scrolling ListView
发布于 2010-04-12 05:10:29
请尝试完全删除该检查。根据我的经验,只有当条目即将出现在屏幕上时,才会调用getView()。
https://stackoverflow.com/questions/2618610
复制相似问题