Android: Speeding up display of (html-formatted) text

Posted by prepbgg on Stack Overflow See other posts from Stack Overflow or by prepbgg
Published on 2011-01-06T18:54:51Z Indexed on 2011/01/06 19:54 UTC
Read the original article Hit count: 233

My app uses a StringBuilder to assemble paragraphs of text which are then displayed in a TextView within a ScrollView.

The displaytext.xml layout file is:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
xmlns:android="http://schemas.android.com/apk/res/android">
<ScrollView
android:id="@+id/ScrollView01"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
>
  <TextView
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/display_text" 
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:textColor="#000000"
      >
  </TextView>
</ScrollView>   
</LinearLayout>

and the code that displays the StringBuilder object sbText is

    setContentView(R.layout.displaytext);
    TextView tv = (TextView)findViewById(R.id.display_text);
    tv.setText(Html.fromHtml(sbText.toString()));

This works OK, except that it gets very slow as the amount of text grows. For example, to display 50 paragraphs totalling about 50KB of text takes over 5 seconds just to execute those three lines of code.

Can anyone suggest how I can speed this up, please?

© Stack Overflow or respective owner

Related posts about android

Related posts about html