android ListView監聽滾動條滾動到底部時繼續加載

listView.setOnScrollListener(new OnScrollListener() {
   
    @Override
    public void onScrollStateChanged(AbsListView view, int scrollState) {
     // 當不滾動時
     if (scrollState == OnScrollListener.SCROLL_STATE_IDLE) {
      //判斷是否滾動到底部
      if (view.getLastVisiblePosition() == view.getCount() – 1) {
       adapter.count += 10; 
                   adapter.notifyDataSetChanged();
                   int currentPage=adapter.count/10;
                   Toast.makeText(getApplicationContext(), "第"+currentPage+"頁", Toast.LENGTH_LONG).show();
      }
     }
    }
   
    @Override
    public void onScroll(AbsListView view, int firstVisibleItem,
      int visibleItemCount, int totalItemCount) {
     // TODO Auto-generated method stub
    
    }
   });

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *