我想只在用户输入不为空时才启用alertDialog肯定按钮,如果用户输入为空则禁用它,为了验证目的切换为王,用户输入不能为空.这是我的代码,即使我把一个字符串按钮没有激活.
buildInfos.setPositiveButton(android.R.string.ok, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
infosDesc = inputInfos.getText().toString();
Log.i("DESC", infosDesc);
drawBetween2LastPoints(getAlertColor(alertType), "title", infosDesc);
}
});
AlertDialog buildInfosDialog = buildInfos.create();
buildInfosDialog.show();
if(infosDesc.isEmpty()){
buildInfosDialog.getButton(Dialog.BUTTON_POSITIVE).setEnabled(false);
}
Run Code Online (Sandbox Code Playgroud)