I am trying to clear a multiline EditText field inside the OnEditorActionListener.onEditorAction method.
But using any of the obvious ways i.e.
((EditText) view).getEditableText().clear();
((EditText) view).getEditableText().clearSpans();
((EditText) view).setText("");
only clears the visible characters - leaving the the newlines in the field (which then have to be manually deleted).
Is there way to 'completely' clear a multiline EditText field ? (or at least - does anybody know why the above don't work ?)
Solved (in a minute after a good night's sleep) - the newline was being added after clearing the text because the onEditorAction method implementation was returning false
(for other reasons).
Returning true
indicates that the 'enter' has been processed/consumed and the clear() behaves as expected:
edittext.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView view,int actionId,KeyEvent event) {
post(view.getText().toString());
((EditText) view).getEditableText().clear();
return true;
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With