I want my App to change it's language to spanish when a user clicks on textview (Spanish), and so on with different langs. Please Help. Thanks
Asked
Active
Viewed 464 times
1 Answers
0
I think its simple :
private void setLocale (String localeCode , Bundle b ){
Locale locale = new Locale(localeCode);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
getApplicationContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
UserDetail.this.getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
onCreate(null);
}
Call the above function from your onclick method over textView, you can set which ever language you want :
...
setLocale("es",savedInstanceState); // for Spanish
setLocale("en-us",savedInstanceState); // for english
...
Hope this helps ...

Abhinav Puri
- 4,254
- 1
- 16
- 28
-
-
-
Thanks! But it says again, "parameter b is never used" . And onClick text view="setLocale" doesn't work too. What to do ?? – Tim Jan 05 '15 at 06:58
-
Well that's okay, you can remove that parameter from function, I used it in my code for some other purpose... – Abhinav Puri Jan 06 '15 at 08:06