使用してみてください:
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();