Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display large amounts of text on Android

Tags:

android

I want to display about one or two full screens worth of text in an Android application (like a welcome screen or help screen), and I'm trying to figure out the best way of storing that text in the app. The text does not need formatting, but line breaks and empty lines must be preserved.

So far I have come up with the following alternatives:

  1. Store the text in a long string in an XML file in res/values, access it like any other string and display it in a TextView. But then what is the proper way of handling line breaks, etc?
  2. Store it in a text file in res/raw, read that from the application and display it in a TextView. Again, do I need to consider line breaks, etc, in this case?
  3. Store it in an HTML file and display it in a WebView. Then how and where should I store the HTML file?

And there are likely more ways that I haven't thought of yet.

Is there a common way of achieving this? I would greatly appreciate sample code as well!

like image 215
Eric Hansander Avatar asked Oct 19 '10 19:10

Eric Hansander


1 Answers

IMHO the most effective way would be setting up one or more strings within the strings.xml and using the \n escape sequence to force a linebreak whenever needed.

If you want to display your data directly as a WebView you should consider storing it within res/html.

But storing an extra text file within res/raw and reading it every time you want to access it doesn't seem very efficient.

like image 171
keyboardsurfer Avatar answered Nov 15 '22 03:11

keyboardsurfer