问题描述
- 如何设置 AlertDialog.Builder 的 NegativeButton 不能点击
-
代码如下:AlertDialog.Builder dialog = new AlertDialog.Builder(this); dialog.setTitle("Dialog"); dialog.setPositiveButton("Check", new DialogInterface.OnClickListener() { public void onClick(DialogInterface arg0, int arg1) { if(condition) { //set NegativeButton unclickable } else { //set NegativeButton clickable } } // end of onClick }); dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface arg0, int arg1) { //do something } });
如何设置 NegativeButton能点击或者不能点击?
解决方案
//设置点击事件
dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
//do something
}
});
//设置点击无效
dialog.setNegativeButton("Cancel", null);
时间: 2025-01-21 10:36:47