很明顯,我有一個我喜歡稱之爲「雞或雞蛋」綜合徵的例子。我試圖找到一種方法來殺死一個警告對話框,該對話框在該過程結束前不會創建。如何在創建之前殺死自定義對話框?
我在做什麼:當問到「您是否要重新下載此圖庫?」時,我想在獲得「是」答案時殺死潛在的彈出窗口(警報/構建器)。但是,當我得到「否」的答案時不行。換句話說,我想在那裏放一個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();
}
直到你指出來......我並沒有真正意識到我將我所有的對話框命名爲「對話框」。一旦我將最上面的對話框重命名爲「mainDialog」,我就可以在OTHER對話框中做一個mainDialog.cancel,我也重命名了它。謝謝您的幫助!! – RayHaque 2011-05-10 13:55:52