嘗試使用:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("message");
builder.setPositiveButton("a", aListener);
builder.setPositiveButton("b", bListener);
builder.setCancelable(false);
builder.show();
注:沒有理由創建另一個AlertDialog
實例。
或者你可以創建方法,另一種正確的做法,返回新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();
包括你的代碼,否則它是不可能知道什麼是錯的 – mdelolmo 2012-07-22 13:27:13
@mdelolmo我同意! :D – 2012-07-22 13:28:20
該代碼似乎沒問題...你的代碼是否正在運行?嘗試添加日誌消息。另外,你的'onPostResume()'方法簽名是什麼樣的? – dmon 2012-07-22 14:01:52