我想显示一个带有确定按钮的消息框。我使用了以下代码,但它会导致带有参数的编译错误:
AlertDialog.Builder dlgAlert = new AlertDialog.Builder(this);
dlgAlert.setMessage("This is an alert with no consequence");
dlgAlert.setTitle("App Title");
dlgAlert.setPositiveButton("OK", null);
dlgAlert.setCancelable(true);
dlgAlert.create().show();
我应该如何在 Android 中显示消息框?
最佳答案
我认为您没有为确定正按钮添加点击监听器可能存在问题。
dlgAlert.setPositiveButton("Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//dismiss the dialog
}
});
关于android - 如何添加带有 'OK' 按钮的消息框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6264694/