Domanda

Hi I have a problem with PreferencesFragment and storing the settings. When I change the phone's language in Android stored values of my preferences are still in the previous language and aren't set in the PreferencesFragment. I have different values folders for each language. What can I do to fix it?

È stato utile?

Soluzione

Well since you want to change the values of the preferences. I don't think it can be done automatically by the API. You will have to write your own code to set the preference values.

You can store the language dependent preference values in values-xx directories. For eg. strings, integers etc.

When someone changes the phone's language your Activity will restarted. You should use this as an opportunity to change the preference values in onCreate. First, store the current language being used, so that it can be used to detect whether the language was changed. You can use the Locale to do it (Locale.getDefalt())

Now, if you detect a language change, just get the values by using the Resources object by calling getResources() and change all the language dependent preference values.

Altri suggerimenti

The Preference language in your application is not dependent on your phone language. If its dependent, you don't even need it in your application , first place. You should make coding in such a way that you have Auto language which depends on phone language.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top