@Override protected void showDialog(Bundle state) { super.showDialog(state); // If the dialog isn't an instance of alert dialog this code is useless if (super.getDialog() instanceof AlertDialog) { final AlertDialog theDialog = (AlertDialog) super.getDialog(); // get originalBottomPadding to know when adjust the underlying // layouts bottom padding (ie has room already // been created for an error message) int padding = Integer.MIN_VALUE; try { padding = ((LinearLayout) getEditText().getParent()).getPaddingBottom(); } catch (Exception e) { // some exception thrown. Unable to do increase space for error // message } final int originalBottomPadding = padding; Button b = theDialog.getButton(AlertDialog.BUTTON_POSITIVE); // attach our validating on click listener ValidatingOnClickListener l = new ValidatingOnClickListener(originalBottomPadding, theDialog); b.setOnClickListener(l); // add an editor action listener for the 'done/next' buttons on a // soft keyboard getEditText().setOnEditorActionListener(l); } }
@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 postiveButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE); // Check if the EditText is empty if (s.length() < mMinLength) { // Disabled OK Button postiveButton.setEnabled(false); } else { // Re-enabled the button. postiveButton.setEnabled(true); } } } }); }
@Override protected void showDialog(Bundle state) { super.showDialog(state); getEditText().removeTextChangedListener(m_watcher); getEditText().addTextChangedListener(m_watcher); }