OnScrollListener回调分析

new AbsListView.OnScrollListener() {
   
   @Override
   public void onScrollStateChanged(AbsListView view, int scrollState) {
    switch (scrollState) {
      case AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL:
             // 手指触屏拉动准备滚动,只触发一次
             Log.i("scroll", "SCROLL_STATE_TOUCH_SCROLL");
          break;
      case AbsListView.OnScrollListener.SCROLL_STATE_FLING:
         // 手指做了抛的动作(手指离开屏幕前,用力滑了一下),只触发一次
             Log.i("scroll", "SCROLL_STATE_FLING");
        break;
          case AbsListView.OnScrollListener.SCROLL_STATE_IDLE:
             // 整个滚动事件结束,只触发一次
             Log.i("scroll", "SCROLL_STATE_IDLE");             
          break;
         default:
         break;
        }
   }

@Override
   public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
     int totalItemCount) {// 一直在滚动中,多次触发  
       //滚动时一直回调,直到停止滚动时才停止回调。单击时回调一次。    
       //firstVisibleItem:当前能看见的第一个列表项ID(从0开始)    
       //visibleItemCount:当前能看见的列表项个数(小半个也算)    
       //totalItemCount:列表项共数       
       boolean isLastRow = false;
       //判断是否滚到最后一行    
       if (firstVisibleItem + visibleItemCount == totalItemCount && totalItemCount > 0) {    
            isLastRow = true;    
      }

Log.i("scroll", "onScroll  "+"firstVisibleItem:"+firstVisibleItem+
        ";visibleItemCount:"+visibleItemCount+";totalItemCount"+totalItemCount+
        ";isLastRow:"+isLastRow); 
      }
  });

上一篇:Node.js + Express + Mongodb 开发搭建个人网站(二)


下一篇:用C语言来验证哥德巴赫猜想(定义的是int型)