我有一个活动(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方法,我在其中放置了我的对话框(为了便于阅读,我移除了一些):
@Override
protected 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;
}