for(inti=0; i < listView.getChildCount(); i++){ Viewchild= listView.getChildAt(i); }
处理空ListView
当数据源为空时,提示无数据
1
listView.setEmptyView(emptyView);
滑动监听
使用OnTouchListener
1 2 3 4 5 6 7 8 9 10 11 12 13
listView.setOnTouchListener(newOnTouchListener(){ publicbooleanonTouch(View v, MotionEvent e){ swicth(e.getAction()){ case MotionEvent.ACTION_DOWN: //按下时操作 break; case MotionEvent.ACTION_MOVE: //移动时操作 break; case MotionEvent.ACTION_UP ://抬起时操作 break; } returnfalse; } });
使用OnScrollListener
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
listView.setOnScrollListener(newOnScrollListener(){ publicvoidonScrollStateChanged(AbsListView view, int scrollState){ //当滑动状态改变时回调 swicth(scrollState){ case OnScrollListener.SCROLL_STATE_IDLE: //滑动停止时操作 break; case OnScrollListener.SCROLL_STATE_TOUCH_SCROLL: //正在滚动 break; case OnScrollListener.SCROLL_STATE_FLING: //手指用力滑动时操作 break; } } publicvoidonScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount){ //滚动时调用 } });
protectedbooleanoverScrollBy(int deltaX, int deltaY, int scrollX, int scrollY, int scrollRangeX, int scrollRangeY, int maxOverScrollX, int maxOverScrollY, boolean isTouchEvent) { returnsuper.overScrollBy(deltaX, deltaY, scrollX, scrollY, scrollRangeX, scrollRangeY, maxOverScrollX, mMaxOverScrollY, isTouchEvent); }