我有一个应用程序,在程序开始时显示免责声明。我想让一个按钮在设置的一段时间内保持不可见,然后变为可见。
我设置了一个线程,让它睡眠5秒钟,然后试图使按钮可见。但是,当我执行代码时,出现以下错误:
08-02 21:34:07.868: ERROR/AndroidRuntime(1401): android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
如何计算5秒钟,然后使按钮可见? 谢谢。
Thread splashTread = new Thread() {
@Override
public void run() {
try {
int waited = 0;
while(_active && (!_ok2)) {
sleep(100);
if(_active) {
waited += 100;
if(waited >= _splashTime)
{
turnButtonOn();
}
}
}
} catch(InterruptedException e) {
// do nothing
} finally {
finish();
startActivity(new Intent("com.lba.mixer.Choose"));
}
};
splashTread.start();
public static void turnButtonOn() {
okButton.setVisibility(View.VISIBLE);
}