問題描述
我有一個帶有 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模板網!