Change EditText text from onTextChangeListener()(从 onTextChangeListener() 更改 EditText 文本)
问题描述
我正在开发一个 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 文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从 onTextChangeListener() 更改 EditText 文本
基础教程推荐
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
