【发布时间】:2014-11-23 12:54:41
【问题描述】:
我只想显示延迟 2 秒的循环中每次迭代的值。
当我运行代码时,主线程冻结,一段时间后只显示tv_t1: 19 的值。
谁能告诉我下面发布的代码中的错误或我遗漏了什么?
注意:
我想在主线程上这样做。
*代码
tv_t1 = (TextView) findViewById(R.id.tv_t1);
tv_t2 = (TextView) findViewById(R.id.tv_t2);
for(int i = 0; i < 20; i++) {
tv_t1.setText("t1:" + i);
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
【问题讨论】:
标签: java android multithreading thread-safety runnable