gpt4 book ai didi

android - onTextChanged 与 Android 中的 afterTextChanged - 需要现场示例

转载 作者:可可西里 更新时间:2023-11-01 19:06:00 25 4
gpt4 key购买 nike

我正在阅读有关 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不允许我这样做
  • onTextChanged 给我更改位置的偏移量,而 afterTextChanged 没有

关于android - onTextChanged 与 Android 中的 afterTextChanged - 需要现场示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26992407/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com