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 文本


- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01