timer.setText("setTextHere")
在線程內不起作用。timer.setText(「setTextHere」)在線程內不起作用
Thread thread1 = new Thread(){
TextView timer;
int t;
public void run(){
timer=(TextView) findViewById(R.id.timer);
try{
timer.setText("setTextHere");
sleep(5000);
}
catch(Exception e){
e.printStackTrace();
}
finally{
Intent new1 = new Intent("com.example.app1.MENU");
startActivity(new1);
}
}
};
thread1.start();
什麼它顯示前初始化的setText ??? – Subburaj 2013-03-18 09:08:58
使用[Activity.runOnUiThread](http://developer.android.com/reference/android/app/Activity.html#runOnUiThread%28java.lang.Runnable%29)用於從線程 – 2013-03-18 09:09:22
訪問或更新UI timer =(TextView )findViewById(R.id.timer);這應該在UI線程中。您只能在UI線程上執行UI更改。 – SKK 2013-03-18 09:10:02