尝试使用:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("message");
builder.setPositiveButton("a", aListener);
builder.setPositiveButton("b", bListener);
builder.setCancelable(false);
builder.show();
注意:没有理由创建另一个AlertDialog
实例。
或者另一种正确的方法,您可以创建返回 new 的方法AlertDialog
:
protected static final int CREATE_INFORMATION_DIALOG = 1320;
private Dialog createDialog(int type) {
AlertDialog dialog = null;
switch (type) {
case CREATE_INFORMATION_DIALOG:
dialog = new AlertDialog.Builder(this)
.setTitle("Information")
.setMessage("Download was finished successfully.")
.setPositiveButton("Close", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dlg, int whichButton) {
}
})
.create();
break;
}
return dialog;
}
然后就这样称呼它
createDialog(CREATE_INFORMATION_DIALOG).show();