由网友(玉砌似画染)分享简介:我试图与线程,但是Android抛出CalledFromWrongThreadException:只有创建视图层次可以触摸其观点原来的线程。I tried with threads, but android throws "CalledFromWrongThreadException: Only the origin...
我试图与线程,但是Android抛出CalledFromWrongThreadException:只有创建视图层次可以触摸其观点原来的线程。
I tried with threads, but android throws "CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.".
所以,我怎么能等待3秒,然后隐藏视图,让图形界面响应?
So how can I wait 3 seconds and then hide the view, letting the GUI responsive?
-
一个定时器使用另一个线程要么,所以它不会解决。
A Timer uses another thread either, so it will not solve..
推荐答案
产卵的睡3秒一个单独的线程然后调用runOnUiThread隐藏的看法。
Spawn a separate thread that sleeps for 3 seconds then call runOnUiThread to hide the view.
Thread thread = new Thread() {
@Override
public void run() {
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
}
runOnUiThread(new Runnable() {
@Override
public void run() {
// Do some stuff
}
});
}
};
相关推荐
最新文章