我正在阅读有关Android编程中的 TextWatcher 的信息。我无法理解afterTextChanged()
和onTextChanged()
之间的区别。
虽然我提到
Differences between TextWatcher 's onTextChanged, beforeTextChanged and afterTextChanged,我仍然无法想到需要使用onTextChanged()
而不是afterTextChanged()
的情况。
最佳答案
我在Android Dev Portal上找到了对此的解释
http://developer.android.com/reference/android/text/TextWatcher.html
**abstract void afterTextChanged(Editable s)**
This method is called to notify you that, somewhere within s, the text has been changed.
**abstract void beforeTextChanged(CharSequence s, int start, int count, int after)**
This method is called to notify you that, within s, the count characters beginning at start are about to be replaced by new text with length after.
**abstract void onTextChanged(CharSequence s, int start, int before, int count)**
This method is called to notify you that, within s, the count characters beginning at start have just replaced old text that had length before.
因此,两者之间的区别是:
afterTextChanged
更改我的文本,而onTextChanged
不允许我这样做