1
@Override
protected void showDialog(Bundle state) {
    super.showDialog(state);

    EditText et = getEditText();
    et.addTextChangedListener(new TextWatcher() {


        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }

        @Override
        public void afterTextChanged(Editable s) {
            Dialog d = getDialog();
            if (d instanceof AlertDialog) {
                AlertDialog dialog = (AlertDialog) d;
                Button positiveButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
                // Check if the EditText is empty
                if (s.length() < mMinLength) {
                    // Disable OK button
                    positiveButton.setEnabled(false);
                } else {
                    // Re-enable the button.
                    positiveButton.setEnabled(true);
                }
            }
        }
    });
}

that showDialog method is not in support library.

How to use EditTextPreference disable buttons by use support library and how to use add change listener on it?

MarianD
  • 13,096
  • 12
  • 42
  • 54

0 Answers0