问题描述
限时送ChatGPT账号..我的游戏中有重启选项.但问题是当我按下重新启动时,现有活动中可能会有一些打开的警报对话框.
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.
当我按下重启时,我想关闭所有打开的 Alertdialog(如果有).我没有任何参考打开警报对话框(可以是 o、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).
有什么方法可以让我随时关闭活动中所有打开的警报对话框而无需任何参考?
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/reference/android/app/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/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 ...
这篇关于如何在没有任何参考的情况下关闭所有打开的警报对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论