2011-05-09 4 views
0

분명히 나는 ​​"닭고기 또는 계란"증후군이라고 부르는 것을 갖고 있습니다. 프로세스가 끝날 때까지 생성되지 않는 경고 대화 상자를 죽일 수있는 방법을 찾으려고합니다.커스텀 대화 상자가 생성되기 전에 어떻게 죽일 수 있습니까?

내가 뭘 하려는지 : "이 갤러리를 다시 다운로드 하시겠습니까?"라는 질문에 "예"라는 대답이 나오면 기본 팝업 (경고/작성기)을 죽이고 싶습니다. 하지만 "아니오"라고 대답 할 때가 아닙니다. 즉, alert.dismiss()를 거기에 넣고 싶습니다 ... 그러나 프로세스의 끝까지 생성되지 않기 때문에 나는 할 수 없습니다.

의미가 있습니까? 나는 이것을 사용자에게 보여 줄 다른 방법을 찾으려고 노력하면서 내 머리를 짚고있다. 시간이 대화 상자가 깃발을 확인하고 구축 할 때

사용자가 예 또는 아니오를 선택하면 그냥 플래그를 설정하지 왜
public void showGalleriesDialogue(String galleriesArray) { 
Log.v("Status","Ran alert dialogue routine."); 
final CharSequence[] items = TextUtils.split(galleriesArray, "\\^"); 

final AlertDialog.Builder builder = new AlertDialog.Builder(MainMenu.this); 
builder.setTitle("Choose a Gallery to download:"); 

builder.setSingleChoiceItems(items, 0, new DialogInterface.OnClickListener() { 
    public void onClick(DialogInterface dialog, int item) { 
     final String galleryToDownload = (String) items[item].toString(); 

     // Check to ensure that this doesn't all ready exist    
     File checkExisists = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/pm-pvault/" + galleryToDownload); 
     Log.v("Status","Checking to ensure that '"+checkExisists+"' does not exist."); 
     if(checkExisists.exists()) { 
       AlertDialog.Builder existsBuilder = new AlertDialog.Builder(MainMenu.this); 
       existsBuilder.setTitle("But wait!"); 
       existsBuilder.setMessage("This gallery already exists. Do you want to RE-INSTALL it?") 
         .setCancelable(false) 
         .setPositiveButton("Yes", new DialogInterface.OnClickListener() { 
          public void onClick(DialogInterface dialog, int id) { 
           // Preview stuff, then go get it. 
           GlobalDataStore.retrycount = 0; 
          preview(galleryToDownload); 
           } 
         }) 
         .setNegativeButton("No", new DialogInterface.OnClickListener() { 
          public void onClick(DialogInterface dialog, int id) { 
           // Never mind. 
           dialog.cancel(); 
          } 
         }); 
       AlertDialog existsAlert = existsBuilder.create(); 
       existsAlert.show(); 
      } 
     //OR ELSE 
     else 
      if(galleryToDownload.contains("@")==true) 
       { 
      AlertDialog.Builder doItNasty = new AlertDialog.Builder(MainMenu.this); 
      doItNasty.setTitle("DISCLAIMER"); 
      doItNasty.setMessage(R.string.nastyDisclaimer) 
        .setCancelable(false) 
        .setPositiveButton("I AGREE", new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, int id) { 
          // Download stuff, go get it. 
          GlobalDataStore.retrycount = 0; 
          preview(galleryToDownload); 
         } 
        }) 
        .setNegativeButton("DISAGREE", new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, int id) { 
          // Never mind. 
          dialog.cancel(); 
         } 
        }); 
      AlertDialog nastyAlert = doItNasty.create(); 
      nastyAlert.show(); 
       } 
       else { 
        // Out of IF conditions to meet. Go download it now. 
        GlobalDataStore.retrycount = 0; 
        preview(galleryToDownload); 
        } 
      } // END OR ELSE 
    } 
}); 
final AlertDialog alert = builder.create(); 
alert.show(); 
} 

답변

0

onClick 이벤트는 콜백이므로 호출 될 때 대화 상자가 이미 존재하므로 취소하는 데 문제가 없어야합니다.

변수 '대화 상자'가 재정의되어 '외부'대화 상자에 액세스 할 수 없습니다.

.setNegativeButton("No", new DialogInterface.OnClickListener() { 
    public void onClick(DialogInterface redownloadDialog, int id) { 
     // Never mind. 
     redownloadDialog.cancel(); 
     dialog.cancel(); 
    } 
}); 
+0

당신이 그것을 지적 할 때까지 ... 나는 대화의 모든 것을 "대화"라고 지칭하면서 내가 무엇을하고 있는지 알지 못했습니다. 가장 위에있는 대화 상자의 이름을 "mainDialog"로 변경하면 OTHER 대화 상자에서 mainDialog.cancel을 수행 할 수있었습니다. 대화 상자의 이름도 변경되었습니다. 도와 주셔서 감사합니다!! – RayHaque

2

, 다음 사용자가 예 다음 돈 선택한 경우 : 여기

내 코드입니다 그것을 만들지 마라. 그런 식으로 당신이 그것을하지 않았기 때문에 그것에 대해 기각하는 것에 대해 걱정할 필요가 없습니다.

+0

나는이 대답을 좋아 :

그것을 같은 일을보십시오. 하지만 이런 방식으로 시도했을 때 작동하지 않았습니다. 프로세스가 끝날 때까지 대화 상자가 만들어지지 않았기 때문에 예/아니요의 상태를 확인하고 해당 응답에 대해 조치를 취할 수있는 플래그를 삽입 할 수 없었기 때문에 동일한 문제에 직면 한 것으로 보입니다. 또한 해당 클래스의 범위를 벗어나는 변수 (예 : GlobalDataStore.flagYES)를 사용해 보았습니다 ...하지만 다시 ... 동일한 문제! – RayHaque

관련 문제