gpt4 book ai didi

Android EditText setText导致软键盘卡住

转载 作者:行者123 更新时间:2023-11-29 15:43:28 24 4
gpt4 key购买 nike

我在使用 EditText 时遇到问题。

我已经实现了一个 TextWatcher 并且我每次都在 afterTextChanged 中检查以突出显示 AsyncTask 中的一些特定关键字并在 中设置文本code>onPostExcute(我这里只接触了UI),但是在onPostExcute中调用setText时软键盘卡住了(应用没有卡住)。

public class AsyncHighLight extends AsyncTask<String,String,String>
{
@Override
protected String doInBackground(String[] p1){
return SyntaxHighlighter.getInstance(MainActivity.this).highlight(p1[0]);
}

@Override
protected void onPostExecute(String result){
et.setText(Html.fromHtml(result));
}
}

高亮代码在这里

public String highlight(String s){
String newString = s;
newString = newString.replace("\n","<br>");
for (int i = 0 ; i < currentLang.keyword.length ; i ++){
newString = newString.replace(currentLang.keyword[i],warpColorTag(currentLang.keyword[i]));
}
return newString;
}

最佳答案

你必须编写终止 TextWatcher 的 afterTextChange() 方法的逻辑,因为每当文本发生变化时,afterTextChange() 就会被调用,每次 afterTextChange() 被调用时,你都会在 AsyncTask 中突出显示一些特定的关键字,并在 onPostExecute 中再次突出显示() 将被调用,它会再次 setText() 。所以你必须找到终止 afterTextChange() 逻辑的方法。如需更好的帮助,请也发布 TextWatcher 代码。

关于Android EditText setText导致软键盘卡住,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36838571/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com