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 文本
基础教程推荐
- 在 iOS8 中无法获得正确的键盘高度值 2022-01-01
- 可可/目标C(OSX不是iOS)从子对象访问父对象 2022-01-01
- Android:STATE_SELECTED不工作 2022-01-01
- 我的 UIImageView 的任务 2022-01-01
- 突出显示朗读文本(在 iPhone 的故事书类型应用程序中) 2022-01-01
- 如何将多个组件添加到 PickerView? 2022-01-01
- - (CGRect)convertRect:(CGRect)rect toView:(UIView *)view 如何工作 2022-01-01
- 在 appComponent dagger 2 中动态添加测试模块? 2022-01-01
- 新的@SystemApi 注解是什么意思,和@hide 有什么区别 2022-01-01
- 在 Android 模拟器中激活网络位置提供程序? 2022-01-01
