本文介绍了TextView 中的长文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个按钮,当我点击它时,我使textView.setText()
成为一个非常大的文本,50000个符号,并且界面停止了3秒,我该如何修复它?
I have a button, and when i click to it, i make textView.setText()
a very big text, 50000 symbols, and the interface stops for 3 seconds, how can i fix it?
- 我尝试使用 Handle 和 thread 来实现,但没有帮助.
我试图制作
textview.append()
,但它也没有帮助.
MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
textText.append(rowItemHeader.getText().substring((endOfNews - 10000, endOfNews));
}
});
编辑 1 没有结果
私有类 MyTask 扩展了 AsyncTask <Void, Void, String>{字符串 str;TextView txt;
MyTask(String str, TextView txt){
this.str = str;
this.txt = txt;
}
public String doInBackground(Void... args) {
return str.substring(endOfNews - 10000, endOfNews);
}
public void onPostExecute(String myString) {
// do your update here or you will get that error (the original thread one)
txt.append(myString);
}
}
推荐答案
首先,删除视图,然后在后台线程中添加文本,然后再添加视图.如果您需要一些示例代码,请告诉我.
First, remove the view, then add the text on background thread, then add the view back. Tell me if you need some sample code.
这篇关于TextView 中的长文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!