我正在开发一个 Android 应用程序.在我的应用程序中,我必须使用基于文本的图像.所以我为 EditText 编写 OnChangeListener().以下是我的示例代码.
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
}
但我收到上述代码的异常.我知道异常的原因是从 afterTextChanged() 方法调用 setText().但是我必须根据相同的 EditText 文本更改来更改 EditText 文本值.帮助我的朋友
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:
添加 onTextChanged 实现后清除 EditText 文本
这篇关于从 onTextChangeListener() 更改 EditText 文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
在android中剪切、复制、粘贴Cut, copy, paste in android(在android中剪切、复制、粘贴)
android EditText 融入背景android EditText blends into background(android EditText 融入背景)
更改 EditText 的线条颜色 - AndroidChange Line Color of EditText - Android(更改 EditText 的线条颜色 - Android)
EditText 始终显示带 2 位小数的数字EditText showing numbers with 2 decimals at all times(EditText 始终显示带 2 位小数的数字)
更改光标在展开的 EditText 中的开始位置Changing where cursor starts in an expanded EditText(更改光标在展开的 EditText 中的开始位置)
android中的EditText,adjustPan,ScrollView问题EditText, adjustPan, ScrollView issue in android(android中的EditText,adjustPan,ScrollView问题)