multi language android application?

I have to make my Android application in 3 languages ie German, English and dutch. i have made three folders in my android application namesvalues-deandvalues-nlwithin the res directory. now when the user selects a specific language i perform the following code:

Resources res = getResources();
Configuration newConfig = new Configuration(res.getConfiguration());
newConfig.locale = Locale.ENGLISH;
res.updateConfiguration(newConfig, null);

all the strings in the different values folders have the same name, i.e a string with name add_site in the values folder has the same name inthe values-defolder but with a different value. My application is not loading the German value when i set the locale to German? what could be the problem?

thank you for you help.

Try putting this inonCreate()just after the call tosuper.onCreate:

Locale locale = new Locale("de");
Configuration config = new Configuration();
config.locale = locale;

EDIT:Here's another approach. It seems to be very flexible, but there seems to be some disagreement in the comments whether it works on all Android versions.

To set the Configuration locale is not enough in case you also support a language which has a different layout direction LTR or RTL.

Resources res = getResources();
        Configuration newConfig = new Configuration( res.getConfiguration() );
        Locale locale = new Locale( appLanguage );
        newConfig.locale = locale;
        newConfig.setLayoutDirection( locale );
        res.updateConfiguration( newConfig, null );
Tags: android, locale
What Others Are Reading