如何实现在Android的分页列表视图 [英] How to implement Paginated List View in Android
问题描述
我想在Android中实现分页列表视图,所以当我向下滚动到最后,每次更多的项目应该添加到我的名单,目前我获取10个项目,从Web服务并显示它们在列表视图,现在我希望增加10多个项目,当用户向下滚动到列表的末尾。 有没有办法做到这一点?
I want to implement Paginated list View in android so when I scroll down to the end, each time more items should add to my list, currently I am fetching 10 items from web service and showing them in a list View, now I want add 10 more Items when user scroll down to the end of the list. Is there any way to do it?
推荐答案
编辑:这一个是更好: <一个href="http://p-xr.com/android-tutorial-dynamicaly-load-more-items-to-the-listview-never-ending-list/" rel="nofollow">http://p-xr.com/android-tutorial-dynamicaly-load-more-items-to-the-listview-never-ending-list/
This one is better: http://p-xr.com/android-tutorial-dynamicaly-load-more-items-to-the-listview-never-ending-list/
-----------------------------------*----------------------
-----------------------------------*----------------------
http://benjii.me/2010/08/endless -scrolling-列表视图功能于安卓/
public class EndlessScrollListener implements OnScrollListener {
private int visibleThreshold = 5;
private int currentPage = 0;
private int previousTotal = 0;
private boolean loading = true;
public EndlessScrollListener() {
}
public EndlessScrollListener(int visibleThreshold) {
this.visibleThreshold = visibleThreshold;
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
if (loading) {
if (totalItemCount > previousTotal) {
loading = false;
previousTotal = totalItemCount;
currentPage++;
}
}
if (!loading && (totalItemCount - visibleItemCount) <= (firstVisibleItem + visibleThreshold)) {
// I load the next page of gigs using a background task,
// but you can call any function here.
new LoadGigsTask().execute(currentPage + 1);
loading = true;
}
}
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
}
这篇关于如何实现在Android的分页列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!