我有一个带有 Customer Text Watcher 的 EditText 字段.在一段代码中,我需要使用 .setText("whatever").
I have an EditText field with a Customer Text Watcher on it. In a piece of code I need to change the value in the EditText which I do using .setText("whatever").
问题是,一旦我进行了更改,就会调用 afterTextChanged 方法,这会创建一个无限循环.如何在不触发 afterTextChanged 的情况下更改文本?
The problem is as soon as I make that change the afterTextChanged method gets called which created an infinite loop. How can I change the text without it triggering afterTextChanged?
我需要 afterTextChanged 方法中的文本,所以不建议删除 TextWatcher.
I need the text in the afterTextChanged method so don't suggest removing the TextWatcher.
你可以注销watcher,然后重新注册.
You could unregister the watcher, and then re-register it.
或者,您可以设置一个标志,以便您的观察者知道您何时自己更改了文本(因此应该忽略它).
Alternatively, you could set a flag so that your watcher knows when you have just changed the text yourself (and therefore should ignore it).
这篇关于如何在不触发 Text Watcher 的情况下更改 EditText 文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
如何检测 32 位 int 上的整数溢出?How can I detect integer overflow on 32 bits int?(如何检测 32 位 int 上的整数溢出?)
return 语句之前的局部变量,这有关系吗?Local variables before return statements, does it matter?(return 语句之前的局部变量,这有关系吗?)
如何将整数转换为整数?How to convert Integer to int?(如何将整数转换为整数?)
如何在给定范围内创建一个随机打乱数字的 intHow do I create an int array with randomly shuffled numbers in a given range(如何在给定范围内创建一个随机打乱数字的 int 数组)
java的行为不一致==Inconsistent behavior on java#39;s ==(java的行为不一致==)
为什么 Java 能够将 0xff000000 存储为 int?Why is Java able to store 0xff000000 as an int?(为什么 Java 能够将 0xff000000 存储为 int?)