Under what circumstances should I use afterTextChanged instead of onTextChanged and vice versa?
Under what circumstances should I use afterTextChanged instead of onTextChanged and vice versa?
public void afterTextChanged(Editable s)
This method is called to notify you that, somewhere within
s, the text has been changed. It is legitimate to make further changes tosfrom this callback, but be careful not to get yourself into an infinite loop, because any changes you make will cause this method to be called again recursively. (You are not told where the change took place because other afterTextChanged() methods may already have made other changes and invalidated the offsets. But if you need to know here, you can usesetSpan(Object, int, int, int)inonTextChanged(CharSequence, int, int, int)to mark your place and then look up from here where the span ended up.
public void beforeTextChanged(CharSequence s, int start, int count, int after)
This method is called to notify you that, within
s, thecountcharacters beginning atstartare about to be replaced by new text with lengthafter. It is an error to attempt to make changes tosfrom this callback.
public void onTextChanged(CharSequence s, int start, int before, int count)
This method is called to notify you that, within
s, thecountcharacters beginning atstarthave just replaced old text that had lengthbefore. It is an error to attempt to make changes tosfrom this callback.
Right from Android's Reference for TextWatcher.