实现对ListView的无尽滚动 [英] Implement Endless scroll on ListView

查看:138
本文介绍了实现对ListView的无尽滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现无尽滚动在Android的ListView组件,当滚动到列表中的最后一个元素,将增加新的项目到列表视图的底部。

I would like to implement endless scroll on an android ListView component, that will add new items to the bottom of the listview when scrolled to the last element in the list.

推荐答案

实现onscrolllistener()

implement the onscrolllistener()

public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
    this.currentFirstVisibleItem = firstVisibleItem;
    this.currentVisibleItemCount = visibleItemCount;
}

public void onScrollStateChanged(AbsListView view, int scrollState) {
    this.currentScrollState = scrollState;
    this.isScrollCompleted();
 }

private void isScrollCompleted() {
    if (this.currentVisibleItemCount > 0 && this.currentScrollState == SCROLL_STATE_IDLE) {
        /*** In this way I detect if there's been a scroll which has completed ***/
        /*** do the work for load more date! ***/
        if(!isLoading){
             isLoading = true;
             loadMoreDAta();
        }
    }
}

为您实现,并添加这个监听到你的ListView这将检测为列表视图的末日,因为滚动位置在列表的末尾只是得到更多的数据。而在加载数据时,你需要一个的标志以一次当滚动位置进入到结束加载数据。因此,如果数据被加载,在这段时间,你向上滚动然后向下滚动,那么它不会得到更多的数据,dupplication。

as you implement and add this listener to your listview this will detect for the end of listview as scroll position was at end of list just get more data. And during the loading data you need one flag to load data at once when the scroll position goes to end. So if data is loading and during that time you scroll up then scroll down then it will not get more data for dupplication.

这篇关于实现对ListView的无尽滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆