2012-09-25 55 views

回答

35

实现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这将检测的ListView的末日,因为滚动位置在列表的末尾刚刚获得更多的数据。在加载数据期间,当滚动位置结束时,您需要一个标志来一次加载数据。因此,如果数据正在加载,并在此期间向上滚动,然后向下滚动,则不会获得更多的数据。

+0

海,u能告诉我如何添加数据时滚动达到在GridView控件。在页面底部wise.i我想这2 weeks.canü帮助我 – ManiTeja

+1

添加数据到您的列表或arraylist或阵列,你已经传递给你的适配器的gridview和数据添加刷新gridview后调用适配器的notifyDataSetChanged()。 – Pratik

+0

以避免多次调用isScrollCompleted我已经调整了使用阈值的方法,即只有当这些项目可见时。 public void onScrollStateChanged(AbsListView view,int scrollState){this。currentScrollState = scrollState; ((jobAdapter.getCount() - (currentFirstVisibleItem + currentVisibleItemCount))<=阈值){ this.isScrollCompleted(); } } – Ajibola