读书人

lisTView分页展示

发布时间: 2012-09-10 11:02:32 作者: rapoo

lisTView分页显示

两种方法 或者根本上一种:

就是当达到一页的最后一个时 在getView() 判断 if position is >= the size of ListAdapter.getCount().

然后就显示另一页

其实也可以

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();?
}?

读书人网 >移动开发

热点推荐