I have a custom adapter for my spinner
:
ArrayAdapter<String> adapter = new ArrayAdapter<String>(context, android.R.layout.simple_spinner_item) {
.............
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
adapter.add(context.getResources().getString(R.string.value1));
adapter.add(context.getResources().getString(R.string.value2));
adapter.add(context.getResources().getString(R.string.hint));
spinner.setAdapter(adapter);
Every thing work as expect but list adapter, when i change the application language every thing got the language change effect but the list adapter don't.
I have the resource for both language.
I'm changing language via this method:
public void setLocale(String lang) {
Locale myLocale = new Locale(lang);
Resources res = getResources();
DisplayMetrics dm = res.getDisplayMetrics();
Configuration conf = res.getConfiguration();
conf.locale = myLocale;
res.updateConfiguration(conf, dm);
}
After i test the case on lower device like lolipop it's worked as well, the current issue with android oreo 8.0.
Since conf.locale = myLocale;
was deprecated in API level 24.
So i didn't use conf.locale = myLocale;
directly. Use getLocales()
and setLocales(LocaleList)
. If only the primary locale is needed, getLocales().get(0)
is now the preferred accessor.
Also updateConfiguration
was deprecated in API level 25, I used createConfigurationContext (Configuration overrideConfiguration)
instead.
But it didn't work, Is i missing something?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…