2017-02-21 7 views
1

ダイアログボックスでフォームを表示しているアラートダイアログビルダーを作成しました。私のポジティブボタン名はサブミットです。フォームのすべてのフィールドが満たされていない限り、ボタンを無効にします。コードは、誰でも助けてくれるはずです。 おかげアラートダイアログビルダのポジティブボタンを無効にする

 alertDialogBuilder.setPositiveButton("SAVE", new DialogInterface.OnClickListener() { 
       @Override 
       public void onClick(DialogInterface dialog, 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<Void> completeQuestionnaireCall = spreadsheetWebService.completeQuestionnaire(nameInput1, nameInput2, nameInput3, nameInput4, nameInput5, nameInput6, nameInput7, nameInput8, nameInput9, nameInput10, nameInput11, nameInput12, nameInput13, nameInput14, nameInput15, nameInput16); 
         completeQuestionnaireCall.enqueue(callCallback); 
         dialog.dismiss(); 

        } 



       } 
      }); 

    alertDialogBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { 
     @Override 
     public void onClick(DialogInterface dialog, int id) { 
      dialog.cancel(); 

     } 
    }); 

    alertDialogBuilder.show(); 
} 

答えて

0

試してみてください。この

alertDialogBu​​ilder.create()getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(偽)。

使用が正のボタンについては、このように行うことができます
0

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

そして、否定ボタン用:

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

あなたがこの方法でこれを行うことができます。

....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); 

・ホープ、この役立ちます。私が正しくあなたの条件を理解している場合

0

あなたは TextWatcher ...

それがうまくいく方法を使用することができます
はあなたのinputfieldsへのテキスト変更のリスナーとしてtextwatcherを追加し、それを保証するであろう
1. Disable button when edittext fields are empty:役立つだろうに応じ

質問「を満たした」されている、あなたはそれを無効に/あなたのボタンの可視性を関連付けるか、有効にすることができ、それらのための動的なチェック 2. Use on text changed listener

0

あなたのUtilsのクラスにすべての入力をチェックしますか

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

今現在のクラスでそれを使用します。また、行うことができます。この

if(checkifEmptyText(new String[]{all your strings}),context) 
{ 
Button button = dialog.getButton(AlertDialog.BUTTON_POSITIVE); 
button.setEnabled(true); 
} 
else 
{ 
Button button = dialog.getButton(AlertDialog.BUTTON_POSITIVE); 
button.setEnabled(false); 
} 
0

のようにそれを確認することができますメソッドを作成これによって:

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(); 
関連する問題