从onTextChangeListener更改的EditText文本() [英] Change EditText text from onTextChangeListener()
问题描述
我在Android application.In工作我的应用我必须使用基于text.So我写的图像 OnChangeListener()
为的EditText
。以下是我的样本code。
I am working on an Android application.In my app I have to use images based on the text.So I write OnChangeListener()
for EditText
.The following is my sample code.
edt.addTextChangedListener(this);
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
CharSequence cs=convert(edt.getText.toString());
edt.setText(cs);
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
}
不过,我收到了超过codeI例外知道异常被调用的原因的setText()
从 afterTextChanged()
方法。但是,我不得不改变基于相同的的EditText
文本值的EditText
文本change.Help我的朋友
But I am getting Exception for the above code.I know the reason for the exception is calling setText()
from afterTextChanged()
method. But I have to change the EditText
text value based on the same EditText
text change.Help me friends
推荐答案
在设置文本之前,只需简单地删除你的监听器,然后重新注册它在完成后,如这里所描述:
Just simply remove your listener before you set the text, and register it again after you are done, like described here:
<一个href=\"http://stackoverflow.com/questions/5567373/clear-edittext-text-after-adding-ontextchanged-implemenation\">Clear文字的EditText添加onTextChanged 实行后
这篇关于从onTextChangeListener更改的EditText文本()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!