用于定時(shí)器的Android線程public class MainActivity extends Activity{int min, sec;/** Called when the activity is first created. */@Overridepublic 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中線程的代碼,但它不起作用。你能幫幫我嗎?它是一個(gè)計(jì)時(shí)器,從5分鐘下降到0:00。
2 回答

倚天杖
TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超3個(gè)贊
UI Thread
Thread
timer1.setText(
runOnUiThread()
, AsyncTask
, CountDownTimer
runOnUiThread()
添加回答
舉報(bào)
0/150
提交
取消