問題描述
我正在開發(fā)一個(gè) Android 應(yīng)用程序.在我的應(yīng)用程序中,我必須使用基于文本的圖像.所以我為 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.
但我收到上述代碼的異常.我知道異常的原因是從 afterTextChanged()
方法調(diào)用 setText()
.但是我必須根據(jù)相同的 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
推薦答案
只需在設(shè)置文本之前移除您的監(jiān)聽器,并在完成后重新注冊,如下所述:
Just simply remove your listener before you set the text, and register it again after you are done, like described here:
添加 onTextChanged 實(shí)現(xiàn)后清除 EditText 文本
這篇關(guān)于從 onTextChangeListener() 更改 EditText 文本的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!