Android_D
Android_D

Reputation: 203

Language change on button click

stucked with one problem that in my application i have one button which is having text SPANISH on it. On the click of this button i want to change the whole application to Spanish language.

Locale mLocale = new Locale("es");
    Locale.setDefault(mLocale); 
    Configuration config = getBaseContext().getResources().getConfiguration(); 
    if (!config.locale.equals(mLocale)) 
    { 
        config.locale = mLocale; 
        getBaseContext().getResources().updateConfiguration(config, null); 
    }

I also have created two separate Strings.xml file. but not got success. I want to change the application language on button click.

Thanks

Upvotes: 3

Views: 2954

Answers (1)

Ahmed Salem
Ahmed Salem

Reputation: 3969

you have to call setContentView() after you change the locale

Upvotes: 5

Related Questions