【发布时间】:2013-06-24 14:25:21
【问题描述】:
我有一个按钮,当我点击它时,我将textView.setText() 变成一个非常大的文字,50000 个符号,并且界面停止了 3 秒,我该如何解决?
- 我尝试使用 Handle 和 thread 制作它,但没有帮助。
-
我尝试制作
textview.append(),但也没有用。MainActivity.this.runOnUiThread(new Runnable() { @Override public void run() { textText.append(rowItemHeader.getText().substring((endOfNews - 10000, endOfNews)); } });编辑 1 无结果
private class MyTask extends AsyncTask <Void, Void, String> {
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);
}
}
【问题讨论】:
-
什么不起作用?变量
myString是否正确阐述? -
它的工作,但我有 1-3 秒的延迟,当我点击按钮。如果我有小文本,它会很快运行,但如果我有非常大的文本,我会延迟。
-
好的,但是你用 AsyncTask 解决了这个问题吗?
-
不,一切都是一样的,我附加了 10000 个符号,我认为 setText() 和 append() 处理大文本的速度很慢。所以,我不能在后台做,我需要在 Ui 线程上做:(