2015-06-09 64 views
0

當滾動到底部時,有一些方法可以加載更多的數據,但我需要通過滾動到android列表頂部來加載數據的方法。 喜歡什麼和另一個聊天應用程序。 你能幫助我嗎?從列表視圖頂部加載更多數據的最佳方法android

+1

請給我們你的努力。問問你面臨的問題。 –

+0

我也需要這個,有什麼建議嗎? –

回答

2

當您滾動到列表視圖的頂部時,下面的邏輯將用於加載更多數據。

listview.setOnScrollListener(new AbsListView.OnScrollListener() { 
     @Override 
     public void onScrollStateChanged(AbsListView view, int scrollState) { 
      currentScrollState = scrollState; 
      if (currentVisibleItemCount > 0 && currentScrollState == SCROLL_STATE_IDLE) { 
       if (currentFirstVisibleItem == 0) { 

        // getMessages(); //write what you want to do when you scroll up to the end of listview. 

       } 
      } 
     } 

     @Override 
     public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,int totalItemCount) { 
      currentFirstVisibleItem = firstVisibleItem; 
      currentVisibleItemCount = visibleItemCount; 
      currentTotalItemCount = totalItemCount; 
     } 
    }); 

希望這會有所幫助。

相關問題