user1143767 user1143767 - 1 year ago 84
Android Question

How can I change the EditText text without triggering the Text Watcher?

I have an

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

The problem is as soon as I make that change the
method gets called which created an infinite loop. How can I change the text without it triggering afterTextChanged?

I need the text in the afterTextChanged method so don't suggest removing the

Answer Source

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).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download