具有非常长的字符串的TextView.setText()阻止UI线程 [英] TextView.setText() with very long string blocks UI thread

查看:55
本文介绍了具有非常长的字符串的TextView.setText()阻止UI线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一个变通方法来解决TextView设置其文本需要花费多长时间?我试图设置一个非常长的字符串,因此它最终将UI线程阻塞了2-3秒钟.由于我无法从其他线程访问TextView,因此我很困惑.

Is there a workaround for how long a TextView takes to set its text? I am trying to set a very long string and it ends up blocking the UI thread for a good 2-3 seconds because of that. Since I can't access the TextView from a different thread, I'm completely stumped.

当前,我在AsyncTask doInBackground()中建立字符串,并在onPostExecute(在uiThread上运行)中 only 调用TextView.setText().TextView放置在ScrollView

Currently, I build up the string inside an AsyncTask doInBackground(), and only call TextView.setText() within the onPostExecute(which is running on the uiThread) The TextView is placed within a ScrollView

推荐答案

即使加载了几个屏幕上的信息,您也不会有问题.如果字符串超长,则可以考虑延迟加载各节中的内容.

You shouldn't have a problem loading even a couple of screens worth of information. If the string is super long, you might consider lazy loading the content in sections.

这篇关于具有非常长的字符串的TextView.setText()阻止UI线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆