Add a TextChangedListener
that will be called every time the text inside the EditText
changes.
message.addTextChangedListener(new TextWatcher() { public void beforeTextChanged(CharSequence s, int start, int count, int after) {} public void onTextChanged(CharSequence s, int start, int before, int count) {} public void afterTextChanged(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( ); } }
In addition, you can also let your class implement the TextWatcher
interface, which makes the code cleaner.
public class MyDialogFragment implements TextWatcher { ... }
source share