使用Handler延时发送消息,发送之后,在HandleMessage方法中,对当前条目进行++处理。当currentItem要越过边界时,将currentItem设置为0
vp_home_conpou = (ViewPager)conpouView.findViewById(R.id.vp_home_conpou);
if(mHandler ==null){
mHandler =new Handler(){
@Override
public void handleMessage(Message msg) {
int currentItem =vp_home_conpou.getCurrentItem();
currentItem ++;
if(currentItem >homeConpous.size() -1){
currentItem =0;
}
vp_home_conpou.setCurrentItem(currentItem);
mHandler.sendEmptyMessageDelayed(0,5000);
};
};
mHandler.sendEmptyMessageDelayed(0,5000);
}
网友评论