如何使AlertDialog消失? [英] How to make an AlertDialog disappear?
问题描述
我正在尝试将Twitter与我的应用程序集成在一起,我想添加一个AlertDialog,该对话框将在用户按下按钮后显示,并且该AlertDialog将询问用户是否要发布推文(所有推文都相同)用户,例如促销推文).我的问题是,是否有任何方法可以使警报对话框在片刻之后(例如5秒钟)消失.
I am trying to integrate Twitter with my application and I thought to add an AlertDialog which will appear after users press a button and this AlertDialog will ask the users if they want to post a tweet(The tweet will be the same for all users, like a promo tweet). My question is if there is any way to make the Alert Dialog disappear after a few moments, like 5 seconds.
我发现了此,但我不确定它是如何工作的.我将不胜感激.
I found this but I am not completely sure how it works. I would appreciate any help.
推荐答案
声明您的Handler
,将在一段时间后关闭对话框,并声明将暂停当前线程并保持对话框一定数量的线程.时间.在线程的Runnable
中,使语句休眠一段时间,例如Thread.sleep(5000);
,然后将Handler对象用于sendMessage()
;在Handler onHandleMessage()
方法中,只需执行dialog.dissmiss();
操作,在要保留对话框的位置,然后使用myThread.start();
启动线程.每次在需要/需要的地方注意线程的实例化.
Declare your Handler
that will deal to dismiss the dialog after some time, and declare thread that will pause the current thread and keep dialog for a some amount of time. In the Runnable
of the thread make a statement that will sleep the thread for a some time, e.g Thread.sleep(5000);
then use the Handler object to sendMessage()
;, in the Handler onHandleMessage()
method just do dialog.dissmiss();
After some operation, at point where you want keep the dialog, and start the thread using myThread.start();
. Mind the instantiation of the thread each time when/where you need.
这篇关于如何使AlertDialog消失?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!