我怎样才能改变文字的EditText不触发文本看守? [英] How can I change the EditText text without triggering the Text Watcher?

查看:586
本文介绍了我怎样才能改变文字的EditText不触发文本看守?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个的EditText 字段上有一个客户文本看守。在一张code,我需要改变,我也使用了的EditText值 .setText(什么)

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.

推荐答案

您可以注销的守望者,然后重新注册。

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

这篇关于我怎样才能改变文字的EditText不触发文本看守?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆