很明显,我有一个我喜欢称之为“鸡或鸡蛋”综合征的例子。我试图找到一种方法来杀死一个警告对话框,该对话框在该过程结束前不会创建。如何在创建之前杀死自定义对话框?
我在做什么:当问到“您是否要重新下载此图库?”时,我想在获得“是”答案时杀死潜在的弹出窗口(警报/构建器)。但是,当我得到“否”的答案时不行。换句话说,我想在那里放一个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