//自动轮播条
private Handler mHandler;
if(mHandler== null){
mHandler = new Handler(){
@Override
public void handleMessage(Message msg) {
//System.out.println("handler...");
int currentItem = mViewPager.getCurrentItem();
if(currentItem<mTopNewsList.size()-1){
currentItem++;
}else{
currentItem=0;
}
mViewPager.setCurrentItem(currentItem);
mHandler.sendEmptyMessageDelayed(0, 3000);
}
};
mHandler.sendEmptyMessageDelayed(0, 3000); //延时3秒钟
class TopNewsTouchListener implements OnTouchListener{
@Override
public boolean onTouch(View v, MotionEvent event) {
switch(event.getAction()){
case MotionEvent.ACTION_DOWN:
mHandler.removeCallbacksAndMessages(null); //删除handler中的所有消息
break;
case MotionEvent.ACTION_CANCEL://事件取消
System.out.println("事件取消");
mHandler.sendEmptyMessageDelayed(0, 3000);
break;
case MotionEvent.ACTION_UP:
mHandler.sendEmptyMessageDelayed(0, 3000);
break;
default:
break;
}
return true;
}
}