Skip to content Skip to sidebar Skip to footer

Android: What Is The Main Idea Behind Of Using Strings.xml?

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'

Solution 1:

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.

Solution 2:

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 forall the strings that the application
  uses, including text for a string named title.

* res/values-fr/strings.xml 
  Contain French text forall the strings, including title.

* res/values-ja/strings.xml
  Contain Japanese text forall 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....

Post a Comment for "Android: What Is The Main Idea Behind Of Using Strings.xml?"