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