1

I have two files: strings.xml (my native language) and string2.xml (English language). Is there a way to, on button click, load one of these files?

For example, on button click if I use file strings.xml then change the default to string2.xml. Or if I use string2.xml, then on click change to string.xml.

Mansfield
  • 14,445
  • 18
  • 76
  • 112
user591097
  • 27
  • 5
  • 1
    Android does that for you automatically depending on the device language. Just create a folder values-xy and put your strings.xml inside, where xy is the language code. – Leo Apr 15 '12 at 14:00

3 Answers3

1
Resources res = context.getResources();
DisplayMetrics dm = res.getDisplayMetrics();
android.content.res.Configuration conf = res.getConfiguration();
conf.locale = new Locale(language_code.toLowerCase());
res.updateConfiguration(conf, dm);

use the above code to update Locale of the app. Just have two folders in res as values-en and values-yournativelanguge and place your string.xml in each folder with name string.xml .

Refer this LINK

Shankar Agarwal
  • 34,573
  • 7
  • 66
  • 64
1

For using multiple language you can use the localization concept.

Here is the link of developer.android.com

http://developer.android.com/resources/tutorials/localization/index.html

Mobile Tech.
  • 729
  • 1
  • 6
  • 16
0

Looking at Load different strings.xml resource on Spinner change It seems like it's possible but you'll have to change the whole locale language of your application.

Community
  • 1
  • 1
Xval
  • 938
  • 5
  • 17