Validation of values in dialogue



  • I have an entry dialogue:

    AlertDialog.Builder inputDialog = new AlertDialog.Builder(context); 
    EditText editText = new EditText(this.myContext); 
    inputDialog.setView(editText); 
    inputDialog.setTitle("Input Dialog"); 
    inputDialog.setMessage("Input new value"); 
    inputDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface _, int __) {
        String value = editText.getText() + "";
        // обработка значения
      }
    });
    inputDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface _, int __) {
      }
      }
    });
    inputDialog.show();
    

    How do you make a button? OK was inaccessible with some user-entered values (from editText?



  • For example,

    Button button = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
    

    if (editText.getText() == "значение") {
    button.setEnabled(false);
    }

    This test may be placed in a clavicle compression listener

    editText.setOnKeyListener(new OnKeyListener() {
    @Override
    public boolean onKey(View v, int keyCode, KeyEvent event) {
    // Проверять здесь
    }
    });

    or add this to the text filter

    filter.addTextChangedListener(new TextWatcher() {
    public void afterTextChanged(Editable s) {
    }
    public void beforeTextChanged(CharSequence s, int start, int count, int after){
    }
    public void onTextChanged(CharSequence s, int start, int before, int count)
    {
    // Проверять здесь
    }
    });




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2