如何显示的图3秒钟,然后将其隐藏? [英] How to show a view for 3 seconds, and then hide it?
本文介绍了如何显示的图3秒钟,然后将其隐藏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图与线程,但是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
}
});
}
};
这篇关于如何显示的图3秒钟,然后将其隐藏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文