4

Possible Duplicate:
Change app language programmatically in Android

I want to change language in my SettingsActivity.java for all Activities immediately.
And save this choice (even when I exit from app or reboot phone) regardless of system locale.
How can I do that?

public class MyOnItemSelectedListener implements OnItemSelectedListener {

    public void onItemSelected(AdapterView<?> parent,
        View view, int pos, long id) { 
        switch (pos) {
        case 0:
            Locale locale = new Locale("en");
            Locale.setDefault(locale);
            Configuration config = new Configuration();
            config.locale = locale;
            getBaseContext().getResources().updateConfiguration(config, getBaseContext()
                    .getResources().getDisplayMetrics());
            break;

        case 1: 
            Locale locale2 = new Locale("de");
            Locale.setDefault(locale2);
            Configuration config2 = new Configuration();
            config2.locale = locale2;
            getBaseContext().getResources().updateConfiguration(config2, getBaseContext()
                    .getResources().getDisplayMetrics()); 
            break;          
        }       
    }

    public void onNothingSelected(AdapterView<?> parent) {
      // Do nothing.
    }
}
3
  • what is your question? Language not changed? Commented Sep 25, 2012 at 12:43
  • changes not to be applied immediately Commented Sep 25, 2012 at 12:47
  • Runtime switching of the language in Android is not supported by default, hence on every configuration change you will have to reset the locale manually. cfr stackoverflow.com/questions/2900023/… Commented Sep 25, 2012 at 13:15

1 Answer 1

2

1) between exit app and reboot you can save choice like this: Create Application class

public class MutawaApplication extends Application {

(http://developer.android.com/reference/android/app/Application.html) register it in AndroidManifest.xml

android:name=".MyApplication"

In this class in onCreate read language from SharedPreferences. Save it to SharedPreferences when you change lang in app.

2) in your Activities check locale on onResume and if need make replaceContentView()

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.