Disabling The Send Button When The Edittext Is Empty When Using Imeoption= Actionsend
When the text is empty, we want to disable the button (which is how it's set on portrait mode) Any ideas? Edit: I don't think it's clear but I can enable/disable my own button.. Bu
Solution 1:
Add a TextChangedListener
which will get called whenever the text inside the EditText
gets changed.
message.addTextChangedListener(new TextWatcher() {
publicvoidbeforeTextChanged(CharSequence s, int start, int count, int after) {}
publicvoidonTextChanged(CharSequence s, int start, int before, int count) {}
publicvoidafterTextChanged(Editable s) {
if (s == null || s.length() == 0) {
send.setEnabled(false);
message.setImeOptions(EditorInfo.IME_FLAG_NO_ENTER_ACTION);
}
else {
send.setEnabled(true);
message.setImeOptions( /* whatever you previously had */ );
}
}
Alternatively, you can also let your class implement the TextWatcher
interface which makes the code a bit cleaner.
publicclassMyDialogFragmentimplementsTextWatcher { ... }
Post a Comment for "Disabling The Send Button When The Edittext Is Empty When Using Imeoption= Actionsend"