Reputation: 7243
I have an EditText
that as an textChangedListener
When I use myEditText.setText("")
two things happen:
texChangedListener
(TextWatcher) is fired.I want to know if there is a way of removing any related events when we use setText()
The first problem I've solved with
if (getWindow() != null) {
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
}
just before myEditText.setText("")
but I still think that should be a way of disabling the events from firing in specific situations.
Any idea for the 2 point or how I should handle this events?
Upvotes: 3
Views: 1512
Reputation: 158
myEditText.removeTextChangedListener(textWatcher);
myEditText.setText("");
myEditText.addTextChangedListener(textWatcher);
Upvotes: 0
Reputation: 416
set the editText change listener to null, then set its text to empty string, and finally set the change listener again.
Upvotes: 3