Android Strings xml stores every value? - android

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.

Related

How do you handle extra strings lines added by translators?

I recently started getting translations into 5 languages for an app I'm working on. When I got the translated strings back, there were a bunch of extra lines added around any tags like <b> or xliff:g. In cases where the text before/after the tag was not a space (e.g. it was punctuation), the extra line causes Android to show an extra space. For example, consider the following string in English:
<string name="welcome_title">Welcome to <xliff:g id="app_name">App Name</xliff:g>!</string>
Pretty simple, right? When a TextView displays this in English, it obviously shows the desired result:
Welcome to App Name!
However, two separate translators (through the Play Store translation service) have now given me back translations that look like the following, e.g. in Spanish:
<string name="welcome_title">
Bienvenido a
<xliff:g id="app_name">App Name</xliff:g>
!
</string>
which causes a TextView displaying this text to show an extra space between "App Name" and the exclamation point:
Bienvenido a App Name !
Practically, this means I have to manually inspect/edit all of the thousands of lines of translations done for me to make sure there aren't extra spaces. Not only is it extremely annoying, but in cases like Arabic, I have no clue how correct any spacing is and it's really hard to know I'm editing correctly.
Has anyone come up with a way to prevent this from happening or clean it up quickly when it does happen? I couldn't find anything on this, but it's early and maybe I haven't had enough coffee! I can't be the only one who's had to deal with this.

How to make searching faster from ArrayList?

I have an ArrayList which has over 15000 Strings which is a line and I am displaying the results with their search words which are displayed using ArrayAdapter but it takes about 6-8 sec to search through the whole ArrayList. Is it possible to make it quicker or at least view the results that are already found and keep the searching continue at the background. Below is the link where I posted the question in detail. I really need help on this any help would be appreciated.
https://stackoverflow.com/questions/20150994/android-how-to-make-searching-initials-of-the-words-from-a-line-in-textfile-fas
I think you need a filterable listview for searching, look this example: List View Filter Android
There are many tips to improve search performance. And you should wrap your data into a model instead of many strings then override equal method for compare two object for searching.
Hi given the use case I under stood that you are searching for the content from a file
which is containing 15,000 lines when user types in the text box. ArrayList is the
efficient data structure to use for search purposes. so the only solution is to divide the
file in to smaller chunks and base on the input read from the expected file and display
the content.
for example:
Pseudo code:
if user types for initials stars with a search in one file
else if user types for initials stars with b search in one file
........................................
........................................
based on use case
else
default file
try in this way check whether performance improves

Android - Appending text lines. Help choose the right control

Folks,
In my social networking application, single-line messages come from various users. As the message comes in, I need to display them in our UI as a single line that shows the time, the user, and the message line. All 3 fields need to be colored differently.
I tried to use TextView but am running into a problem. As I need various colors, I thought of using SpannableString but the problem is that TextView.Append does not support SpannableString as a parameter.
The other thought I had was to build html style text as each line comes in.
I am wondering if I am overlooking something. Perhaps there is a better user control or a better way to achieve my objective.
Thank you in advance for your help.
Regards,
Peter
Use Html and with help of <font color><font/> tag, you can set single text with different color#
String result="<font color=color_code>First Textview</font> <font color=color_code>Second Textview</font><font color=color_code>Third TextView</font>";
textview.setText(Html.fromHtml(result));
You should use three different text fields, nest them in a table layout using columns, or a relative layout. That way they will automatically resize no matter what length.
You can also use the android:weight tag to control how much room each one takes up.
The reason is that usually its 1 label per field in data structure. As per MVC software design pattern.

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.

How to display large amounts of text on 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.

Categories

Resources