内onTextChanged的Andr​​oid电话的setText [英] Android call setText within onTextChanged

查看:232
本文介绍了内onTextChanged的Andr​​oid电话的setText的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要prevent无限循环我做了一件丑陋的,因为这...

To prevent the infinite loop I did something as ugly as this...

    @Override
protected void onTextChanged(CharSequence text, int start,
        int lengthBefore, int lengthAfter) {

    String t = text.toString();
    String tt = t.toUpperCase();

    if (!t.equals(tt)) {

        setText(tt);
    }

    super.onTextChanged(text, start, lengthBefore, lengthAfter);
}

是否有任何其他方式prevent的 onTextChanged 更改在 onTextChanged 的文本时被调用?

Is there any other way to prevent the onTextChanged from being called when changing the text within onTextChanged?

推荐答案

您可以使用指定如果文本已更改一次与否的标志。如果已更改一次,然后不再次更改,否则更改。

You could use flags that specify if the text has been changed once or not. If it has been changed once, then do not change again, else change it.

int flag_text=0;
protected void onTextChanged(CharSequence text, int start,
    int lengthBefore, int lengthAfter) {

    if (flag_text==0) {
        flag_text=1;
        setText(tt);
    }
    super.onTextChanged(text, start, lengthBefore, lengthAfter);
}

这篇关于内onTextChanged的Andr​​oid电话的setText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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