2012-09-19 6 views
1

사용자가 측정 값에 대한 일부 값을 입력하고 sqlite 데이터베이스에 저장하는 활동 (ImportActivity)이 있습니다.경고 대화 상자가 표시됩니까? 첫 번째가 없습니다! android

사용자가 데이터베이스로 가져온 후 저장 버튼을 클릭하면 사용자가이 활동을 떠나거나 다른 measure를 가져올 수있는 경고 대화 상자 (SAVEORBACK_DIALOG_ID)가 있습니다. 완벽하게 작동합니다.

내 문제는 (SAVEORBACK_DIALOG_ID) 경고 대화 상자 바로 전에 다른 경고 대화 상자 (SMS_DIALOG_ID)를 표시하려고 할 때 발생합니다. 사용자에게 보내거나 보내지 말 것을 요청하기 때문입니다.

실행할 때 두 번째 경고 대화 상자 만 표시됩니다 (SAVEORBACK_DIALOG_ID) !!

ImportActivity this is final dialog

나는 활동이 : 내 활동에서 호출

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; 
} 

답변

6

이 명령은 사용자가 눈치로, 첫 번째 대화를 덮어하는, 연속적으로 실행됩니다 두 번째를 표시하기 전에 첫 번째 대화의 응답을 기다리지 않습니다

// 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; 
} 
관련 문제