0

I am working on an app where I am trying to change the language inside the app with a preference screen and using a preferenceList. I am able to listen to the choices, but I can't seem to recreate the "parent" class. Everywhere I changed the language by setting language choice in onCreate(...). But how would you update the language in the activity you are currently in? I listen to changes in language choice in a static class like this :

public class PrefActivity extends PreferenceActivity {

  @Override
  public onCreate(Bundle savedInstanceState) {
    //Code
  }
  
  public static class PreferenceFrag extends PreferenceFragment {
    //onCreate method

    .... SharedPreferences.OnSharedPreferenceChangeListener() {
       @Override
       public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) {
         //Reads the changes and sets new locale
         //How would you make the changes come instant to the R.xml.Preference
    }
  }
}
rzwitserloot
  • 85,357
  • 5
  • 51
  • 72
Jacob
  • 1
  • 1
  • Note that if you have a static inner class there is no special relation to the outer class and thus it's just something like a namespace. Your inner class would thus need to get a reference to an instance of the outer class (current activity). I'm not that familiar with Android development but think about whether the inner fragment class needs to be static. – Thomas Sep 16 '20 at 21:43
  • Make it an inner class, i.e. remove `static`. NB `static inner` is a contradiction in terms @Thomas. – user207421 Sep 16 '20 at 22:13
  • @MarquisofLorne you're right, my bad. I was using "inner" as "inside another class" but the correct term would be "static nested" - and "inner" would be "non-static nested" ([as defined by Oracle](https://docs.oracle.com/javase/tutorial/java/javaOO/nested.html)) – Thomas Sep 16 '20 at 22:17
  • Maybe I asked the wrong question, but it seems like I had to be static cause it implemented PreferenceFragment. But I think I found the solution by using `code`getActivity().reacreate(); – Jacob Sep 17 '20 at 14:09

1 Answers1

0

Think I found the answers by using this as follow:

getActivity().recreate();
Mikheil Zhghenti
  • 734
  • 8
  • 28
Jacob
  • 1
  • 1