android对话框加“确定”,“取消”两个按钮,却总只显示一个怎么回事?

2024-11-22 00:35:29
推荐回答(1个)
回答1:

protected void dialog() {
AlertDialog.Builder builder = new Builder(Main.this);
builder.setMessage("确认退出吗?");
builder.setTitle("提示");
builder.setPositiveButton("确认", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
Main.this.finish();
}
});
builder.setNegativeButton("取消", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.create().show();
}

你的连个都是 builder.setPositiveButton()当然只会显示一个了 呵呵