【发布时间】:2013-07-24 16:10:55
【问题描述】:
public class MainActivity extends Activity
{
int min, sec;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
min = 5;
sec = 0;
final TextView timer1 = (TextView) findViewById(R.id.timer1);
timer1.setText(min + ":" + sec);
Thread t = new Thread() {
public void run() {
sec-=1;
if (sec<0) {
min-=1;
sec=59;
}
timer1.setText(min + ":" + sec);
try
{
sleep(1000);
}
catch (InterruptedException e)
{}
}
};
t.start();
}
}
这是 Java 线程的代码,但它不起作用。你能帮帮我吗?
它是一个从 5 分钟倒计时到 0:00 的计时器。
【问题讨论】:
-
您不认为 Timer 会是更好的选择吗? developer.android.com/reference/java/util/Timer.html
-
您尝试过发布的任何解决方案吗?