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:
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?
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?
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!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With