尝试使用:
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