android定时滚动

final Handler autoGalleryHandler = new Handler() {
public void handleMessage(Message message) {
super.handleMessage(message);
switch (message.what) {
case 1:
galleryFlow.setSelection(message.getData().getInt("pos"));

break;
}
}
};

Timer autoGallery = new Timer();
autoGallery.schedule(new TimerTask() {
int gallerypisition = 0;
@Override
public void run() {
if (gallerypisition < adapter.getCount() - 1) {
gallerypisition = gallerypisition + 1;
} else {
gallerypisition = 0;
}

Message msg = new Message();
Bundle date = new Bundle();// 存放数据
date.putInt("pos", gallerypisition);
msg.setData(date);
msg.what = 1;//消息标识
autoGalleryHandler.sendMessage(msg);
}
}, 0, 3000);//5秒后,每隔5秒执行信息发送

你可能感兴趣的:(android)