問題描述
我正在開發一個 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模板網!