Someone please explain what is the main idea of using strings.xml? I think it would be useful for multi-language support but how can we organise it for that? Do I need it if I don't want to use multi-language support in my android application?
A string resource provides text strings for your application with optional text styling and formatting. There are three types of resources that can provide your application with strings: String. XML resource that provides a single string.
xml , you can easily translate your whole app into other languages. This saves you a lot of work instead of doing this the hardcoded way: Android automatically selects the correct language based on user preferences, and you don't have to worry about selecting and displaying this language.
It allows you to easily locate text in your app and later have it translated. Strings can be internationalized easily, allowing your application to support multiple languages with a single application package file (APK).
The XML resource files containing localized strings are placed in subfolders of the project's res folder.
The idea is that it represents a single location for various strings, so your code isn't peppered with string literals. In addition to that, you gain the ability to easily localize. Organization of files for localization is covered here:
http://developer.android.com/guide/topics/resources/localization.html#creating-alternatives
Do you need it if you're not localizing? No. But it may make things easier in the long run, and I would recommend using it just for that reason.
Hard-coding strings is Bad.
Parameterizing strings (e.g. with strings.xml) is Good.
Being able to internationalize your strings (with language and/or locale-specific versions of strings.xml) is even Better :)
PS:
To make use of internationalization, just create resource subdirectories. Google will give you plenty of references/examples. Herre's one:
http://developer.android.com/guide/topics/resources/localization.html
* res/values/strings.xml
Contains English text for all the strings that the application
uses, including text for a string named title.
* res/values-fr/strings.xml
Contain French text for all the strings, including title.
* res/values-ja/strings.xml
Contain Japanese text for all the strings...
And yes, you should absolutely get in the habit of using strings.xml (and colors.xml and dimens.xml etc etc) even if you don't plan on internationalizing immediately.
IMHO....
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