How to display large amounts of text on Android - 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:
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?
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?
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!

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.

Related

Inverse/Reverse of Html.fromHtml(String)

I am creating a note application for myself. To style my notes, I write html tags, click a button and show styled version with html. from html.. But the problem is, I need to store the text with html tags not without it so when I get the data from the database, I get the text with style.
So I wonder is there any way to decode embedded html tags other than storing the string before html. from html function and acting accordingly? Also i can click the button anytime then continue typing which is very hard to track. Because i run this function to stylize ;
text.setText(Html.fromHtml(text.getText().toString()));
Which means i lose the tag info.
Thanks in advance.
If the user of the app write the html tags, the app should store them.
So as you suggest yourself, you will have to store the string before calling Html.fromHtml.

Android Strings xml stores every value?

Do we have to place every text that we have to type in buttons or inputs or on plain surface of an activity.what happens if we don't provide values of text strings to strings xml??
what happens if we don't provide values of text strings to strings
xml??
you will get a lot of warnings from lint and no strings localization
Using strings.xml is mainly for localization, it's easy to translate a XML file and use it, not using strings.xml is a headache later on when you want to translate your app.
You may not use it, but maybe later you'll regret it.
Besides localization, it's very handy to have all strings located in the same place, when for instance, you have to change some label or correct some messages displayed to users.
Looking for strings in the code afterward could be a real pain when thousand of lines of code are produced.

How to display a lot of text lines

I am working on an Android app for tourists where I show a list of all rooms in my city for accomodation. I have approximately 500 lines of text, about 5 lines for each room (adress, phone number, contact person, email adress and stars rating). I want to put all that text in one activity so you can scroll and read that text.
Should I use TextView or something else? Should I save that whole text in res/strings.xml?
There is no problem with using TextViewsjust do not forgot about using ScrollView for your layout so you can scroll your TextViews.
You could use a WebView and display the text in HTML format.
I did it for big documents and used the assets folder to store and load the document.
Internationalization can be kept using following technique:
What's the best practice to deploy localized documents in Android app?

Is there a way to store and display HTML with CSS to achieve text formatting in Android?

I'm creating a note taking app for Android and i would like the user to be able to format their text, i.e. bold, different text sizes.
What I would like to know is how can I do this bearing in mind the text will have to be store-able in a database.
Can i use a web view with a string of HTML i pull from the database and a custom defined CSS to style it on the user end?
I also know there is some sort of formatting class in Android but im unsure of how it work, im not convinced it would be easy to store the formatting information.
I think you should use Spannable text. See android.text.*. I think you should store the text in HTML markup. Also take a look at
http://developer.android.com/guide/faq/commontasks.html#selectingtext

Android - EditText to StringArray stored in xml

Ive been attempting to work out how to take the text from an edittext box and move it into a string array located in strings.xml.
Basically its a user form which the user fills in, onClick it adds the information to the database and is then viewable in a listview. The listview and everything works fine but i cant work out to put in information using edittext boxes.
Any hints or techniques would be very much appreciated.
Thanks
You want to take user input for an edit text, and put it in strings.xml? You can't do that. String resources are for static strings, not things that will change at runtime. You should look at other data storage options, like shared preferences. See data storage.
I could be wrong (someone please correct me if I am), but I don't believe strings.xml is editable at runtime. Rather, it's a set of predefined resources that your app has access to, and it cannot be modified by the program--only read.
If you're looking to make this information available to your app for subsequent uses, you should look at using SharedPreferences: http://developer.android.com/guide/topics/data/data-storage.html#pref
No way. You can't do such a thing. Surely not with strings.xml and androidmanifest.xml too.
The other option you have is: if you already have some values in strings.xml, you can fetch them in an list and append your own values that you want from user. After that, put it in an adapter and display it in a list view like you usually do.

Categories

Resources