I have an annoying problem with TextWatcher. i've been searching the web but couldnt find anything. appreciate if someone could assist me.
For some reason the calls to the TextWatcher events upon one text change are erratic. sometimes they are being triggered once (like they should be), sometimes twice, and sometimes 3 times. have no idea why, the whole thing is very straight forward. also sometimes the Editable parameter on afterTextChanged() returns empty values in toString() and length().
code is below:
private TextWatcher mSearchAddressTextChangeListener = new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) { }
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) { }
@Override
public void afterTextChanged(Editable searchedAddress) {
System.out.println("called multiple times.");
}
};
inside afterTextChanged()
(and the AsyncTask
) im not making any change to the text or the EditText
view.
i saw the question asked in Events of TextWatcher are being called twice, but im having the events triggered more (or less) than twice.
anyway, appreciate any help.
EDIT: I removed the content of afterTextChanged() cause this problem is happening even without my code. what leads me to believe this is a bug. The bug is occuring when a 'space' char is entered right after a regular char (event handlers are triggered twice) or when a 'space' char after a regular char is removed (backspace. event handlers are triggered 3 times). help will still be appreciated.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…