实现对ListView的无尽滚动ListView

由网友(傲世战场)分享简介:我想实现无尽滚动在Android的ListView组件,当滚动到列表中的最后一个元素,将增加新的项目到列表视图的底部。I would like to implement endless scroll on an android ListView component, that will add new items t...

我想实现无尽滚动在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.

阅读全文

相关推荐

最新文章