Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/hadoop/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 禁用警报对话框生成器中的积极按钮_Android_Android Alertdialog - Fatal编程技术网

Android 禁用警报对话框生成器中的积极按钮

Android 禁用警报对话框生成器中的积极按钮,android,android-alertdialog,Android,Android Alertdialog,我已经创建了一个警报对话框生成器,在对话框中显示一个表单。我的肯定按钮名为submit。我希望该按钮被禁用,除非表单中的所有字段都已填写。下面是我的代码。有人能帮我解决这个问题吗。 谢谢 alertDialogBuilder.setPositiveButton(“保存”,新建DialogInterface.OnClickListener(){ @凌驾 public void onClick(DialogInterface对话框,int-id){ nameInput1=data_txt1.getT

我已经创建了一个警报对话框生成器,在对话框中显示一个表单。我的肯定按钮名为submit。我希望该按钮被禁用,除非表单中的所有字段都已填写。下面是我的代码。有人能帮我解决这个问题吗。 谢谢

alertDialogBuilder.setPositiveButton(“保存”,新建DialogInterface.OnClickListener(){
@凌驾
public void onClick(DialogInterface对话框,int-id){
nameInput1=data_txt1.getText().toString();
nameInput2=data_txt2.getText().toString();
nameInput3=data_txt3.getText().toString();
nameInput4=data_txt4.getText().toString();
nameInput5=data_txt5.getText().toString();
nameInput6=auto_txt1.getText().toString();
nameInput7=auto_txt2.getText().toString();
nameInput8=auto_txt3.getText().toString();
nameInput9=auto_txt4.getText().toString();
nameInput10=auto_txt5.getText().toString();
nameInput11=auto_txt6.getText().toString();
nameInput12=auto_txt7.getText().toString();
nameInput13=auto_txt8.getText().toString();
nameInput14=auto_txt9.getText().toString();
nameInput15=data_txt6.getText().toString();
nameInput16=data_txt7.getText().toString();
Call completeQuestionnaireCall=Spreadsheet WebService.CompleteQuestion(名称输入1、名称输入2、名称输入3、名称输入4、名称输入5、名称输入6、名称输入7、名称输入8、名称输入9、名称输入10、名称输入11、名称输入12、名称输入13、名称输入14、名称输入15、名称输入16);
completeQuestionnaireCall.enqueue(CallCallCallback);
dialog.dismise();
}
}
});
alertDialogBuilder.setNegativeButton(“取消”,新建DialogInterface.OnClickListener()){
@凌驾
public void onClick(DialogInterface对话框,int-id){
dialog.cancel();
}
});
alertDialogBuilder.show();
}

试试这个


alertDialogBuilder.create().getButton(AlertDialog.BUTTON_正数)。setEnabled(假)

对于正极按钮,可以这样使用:

dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setEnabled(false);
对于负片按钮:

dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setEnabled(false);

您可以通过以下方式执行此操作:

    ....your code for alert dialog
    AlertDialog dialog = b.create(); // here b is reference of AlertDialog.Builder and in your case replace b with alertDialogBuilder
    dialog.show();
    Button button = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
    button.setEnabled(false);

希望这会有所帮助。

如果我正确理解您的要求

你可以用

工作原理:
将textwatcher作为文本更改的侦听器添加到您的输入字段中,这将确保动态检查这些字段是否“已填充”,您可以关联按钮的可见性或相应地启用/禁用它

有帮助的问题:


创建一个方法,该方法将检查Utils类中的所有输入,或者可以在当前类中使用它

public static boolean checkifEmptyText(String[] fields,Context context) {
    for (String currentField : fields) {
        if (currentField.getText().toString().trim().length() <= 0) {
            return false;
        }
    }
    return true;
}

您也可以这样做:

new AlertDialog.Builder(this)
    .setMessage("This may take a while")
    .setPositiveButton("OK", new android.content.DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
         ((AlertDialog)dialog).getButton(which).setVisibility(View.INVISIBLE);
         // the rest of your stuff
    }
})
    .show();