Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is WebView so much faster than a TextView

I have an activity that's supposed to display a text file. The text file is 165 kB. Originally, after I read in the text file, I would do something like this,

textView.setText(fileText);

But that took over 10 seconds on my Nexus 4, and I confirmed that this was due to the call to setText() and not reading the file. Then, after searching around a bit, I got the idea to put it in a webview, using WebView.loadData(). This takes less than a second.

I'm curious as to why a WebView is able to load text so much faster than a TextView. Does anyone know?

like image 322
gsingh2011 Avatar asked Nov 01 '22 10:11

gsingh2011


1 Answers

From what I remember;

The WebView will only render the text that it needs to display at any given time. Meaning that when you first load it will only load 20 - 30 lines of text. Whereas when you call textView.setText(fileText); it causes Android to render all of the text even though it is not displayed. If you are trying to add a lot of text to a TextView then you should use textView.append(fileLine); in a loop which should load quite a bit faster.

like image 112
RocketSpock Avatar answered Nov 08 '22 04:11

RocketSpock