2012-09-25 34 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