Farid Movsumov
Farid Movsumov

Reputation: 12735

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't want to use multi-language support in my android application?

Upvotes: 5

Views: 3080

Answers (2)

paulsm4
paulsm4

Reputation: 121881

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....

Upvotes: 5

David Merriman
David Merriman

Reputation: 6086

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.

Upvotes: 11

Related Questions