java– 另一个警告对话框后的警报对话框?第一个缺失!安卓

java– 另一个警告对话框后的警报对话框?第一个缺失!安卓,第1张

概述我有一个活动(ImportActivity),其中用户输入一些度量的值并将它们保存到sqlite数据库中.当用户在导入到数据库后单击“保存”按钮时,我有一个警告对话框(SAVEORBACK_DIALOG_ID),用户可以在此处离开此活动或导入另一个度量.它工作正常.我的问题是当我尝试在(SAVEORBACK_DIALOG_ID)

我有一个活动(importActivity),其中用户输入一些度量的值并将它们保存到sqlite数据库中.

当用户在导入到数据库后单击“保存”按钮时,我有一个警告对话框(SAVEORBACK_DIALOG_ID),用户可以在此处离开此活动或导入另一个度量.它工作正常.

我的问题是当我尝试在(SAVEORBACK_DIALOG_ID)警告对话之前显示另一个警报对话框(SMS_DIALOG_ID).这是因为我想要求用户发送或不发送短信.

当我运行它时它只显示第二个警告对话框(SAVEORBACK_DIALOG_ID)!

我在活动中:

    static final int DATE_DIALOG_ID = 0;static final int TIME_DIALOG_ID = 1;static final int SAVEORBACK_DIALOG_ID = 2;static final int SMS_DIALOG_ID = 3;

我从我的活动中打电话给他们:

        // sms dialog(send sms to doctor?yes/no)        showDialog(SMS_DIALOG_ID);        // save or back dialog        showDialog(SAVEORBACK_DIALOG_ID);

这是onCreateDialog方法,我有我的对话框(我删除了一些更容易阅读):

    @OverrIDeprotected Dialog onCreateDialog(int ID) {    switch (ID) {    case DATE_DIALOG_ID:        return new DatePickerDialog(this, mDateSetListener, mYear, mMonth,                mDay);    case TIME_DIALOG_ID:        return new TimePickerDialog(this, mTimeSetListener, mHour, mMinute,                false);    case SAVEORBACK_DIALOG_ID:        AlertDialog.Builder builder = new AlertDialog.Builder(this);        builder.setMessage(                "information saved successfully ! Add Another Info?")                .setCancelable(false)                .setPositivebutton("No",                        new DialogInterface.OnClickListener() {                            public voID onClick(DialogInterface dialog,                                    int ID) {                                importActivity.this.finish();                            }                        })                .setNegativebutton("Yes",                        new DialogInterface.OnClickListener() {                            public voID onClick(DialogInterface dialog,                                    int ID) {                                dialog.cancel();                                // get the new date                                // Clearing the fIElds & update date/time                                // textvIEws                            }                        });        AlertDialog dialog = builder.create();        return dialog;        // case sms dialog    case SMS_DIALOG_ID:        AlertDialog.Builder builder2 = new AlertDialog.Builder(this);        builder2.setMessage("High blood pressure ! Send sms to doctor?")                .setCancelable(false)                .setPositivebutton("No",                        new DialogInterface.OnClickListener() {                            public voID onClick(DialogInterface dialog,                                    int ID) {                                dialog.cancel();                                // do nothing - just continue                            }                        })                .setNegativebutton("Yes",                        new DialogInterface.OnClickListener() {                            public voID onClick(DialogInterface dialog,                                    int ID) {                                dialog.cancel();                                // try to send sms - report status                            }                        });        AlertDialog dialog2 = builder2.create();        return dialog2;        //    }    return null;}

解决方法:

这些命令是连续执行的,正如您所注意到的那样,它会覆盖第一个对话框:

    // sms dialog(send sms to doctor?yes/no)    showDialog(SMS_DIALOG_ID);    // save or back dialog    showDialog(SAVEORBACK_DIALOG_ID);

因为showDialog()在显示第二个对话框之前不会等待第一个对话框的响应.

只需将第二个showDialog()命令移动到第一个对话框中的按钮:

.setPositivebutton("No",    new DialogInterface.OnClickListener() {        public voID onClick(DialogInterface dialog, int ID) {            dialog.cancel();            // do nothing - just continue            importActivity.this.showDialog(SAVEORBACK_DIALOG_ID);        }    })// etc, etc

或者,您可以使用OndismissDialogListener,只要关闭对话框(通过按钮单击,取消 *** 作等),就会调用此方法:

case SMS_DIALOG_ID:    ...    AlertDialog dialog2 = builder2.create();    dialog2.setondismissListener(new OndismissListener() {        public voID ondismiss(DialogInterface dialog) {            importActivity.this.showDialog(SAVEORBACK_DIALOG_ID);        }    });    return dialog2;}
总结

以上是内存溢出为你收集整理的java – 另一个警告对话框后的警报对话框?第一个缺失!安卓全部内容,希望文章能够帮你解决java – 另一个警告对话框后的警报对话框?第一个缺失!安卓所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1095937.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存