TextView.setText () with very long lines blocks the UI thread

Is there a workaround for how long a TextView takes to set its text? Because of this, I am trying to set a very long line, and because of this, it blocks the user interface flow for 2-3 seconds. Since I cannot access the TextView from another thread, I completely stalled.

Edit: I am currently creating a line inside AsyncTask doInBackground () and only calls TextView.setText () inside onPostExecute (which is running on uiThread). TextView fits in ScrollView

+4
source share
2 answers

You should not have problems loading even multiple screens. If the line is very long, you can consider lazy loading content in sections.

+3
source

Since I cannot access the TextView from another thread,

You can use another Thread and still access the TextView . Not knowing your code is hard to give a good example, but you can use runOnUiThread

or

you can use AsyncTask . By doing this this way, you can do everything you need in doInBackground() and set the text to onPostExecute()

Although, I'm not sure how long your line will take several seconds to load. If you do a lot of work to assemble a string, I would suggest using AsyncTask

-1
source

Source: https://habr.com/ru/post/1487934/


All Articles