Android的Alertbox如何解雇没有任何引用所有打开的Alertbox [英] Android Alertbox How to dismiss all open Alertbox without any references
问题描述
我在游戏中的重新启动选项。但问题是,有可能在现有活动一些开放alertdialog当我preSS重启。
I have a restart option in my game. but the problem is that there may be some open alertdialog in the existing activity when I press restart.
当我preSS重启我想关闭所有打开的Alertdialog(如果有的话)。我没有打通alertdialogs任何引用(可以是0,1个或多个)。
When I press restart I want to dismiss all open Alertdialog(if any). I do not have any reference to opened up alertdialogs(Can be o,1 or more than one).
有没有什么办法可以关闭所有在任何时间活动开辟了alertdialogs无需任何参考?
Is there any way I can dismiss all the opened up alertdialogs in the activity at any time without having any reference to it ?
推荐答案
首先,你可以所有的对话分配给一个成员变量,例如
First you could assign all your dialogs to a member variable, e.g.
private Vector<AlertDialog> dialogs = new Vector<AlertDialog>();
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DIALOG_ALERT:
Builder builder = new AlertDialog.Builder(this);
...
AlertDialog dialog = builder.create();
dialogs.add(dialog);
dialog.show();
}
return super.onCreateDialog(id);
}
之后,您可以测试对话框是否显示或不使用对话框的 isShowing()
办法(检查出从类继承的方法 android.app.Dialog
http://developer.android .COM /参考/安卓/应用/ AlertDialog.html ),例如:
Afterwards, you can test whether dialogs are showing or not by using the isShowing()
method of your dialogs (check out inherited methods from class android.app.Dialog
http://developer.android.com/reference/android/app/AlertDialog.html), e.g.
public void closeDialogs() {
for (AlertDialog dialog : dialogs)
if (dialog.isShowing()) dialog.dismiss();
}
或者你可以完成并重新启动您的活动为 Pragnani 的说。取决于你在哪里重启按钮...
Or you might finish and start your activity again as Pragnani said. Depends on where your restart button is ...
这篇关于Android的Alertbox如何解雇没有任何引用所有打开的Alertbox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!