使用java.util.Timer来周期性的执行制定的任务

使用java.util.Timer来周期性的执行制定的任务

 public class HandlerTest extends Activity {
int[] images = new int[] {
R.drawable.baiyang, R.drawable.jinniu, R.drawable.shuangyu
}; int currentImageID = 0; @Override
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.imageview);
final ImageView imageView = (ImageView) findViewById(R.id.imageViewtest); final Handler myHandler = new Handler() { @Override
public void handleMessage(Message msg) {
if (msg.what == 0x123) {
imageView.setBackgroundResource(images[currentImageID++ % images.length]);
}
} }; new Timer().schedule(new TimerTask() { @Override
public void run() {
myHandler.sendEmptyMessage(0x123); }
}, 0, 1000); } }
上一篇:初识Android NDK


下一篇:Python实现,从txt取出号码,在数据库里查询此号码是否存在