tags:

views:

47

answers:

1

I had read about localization here: http://developer.android.com/guide/topics/resources/localization.html But I need to switch language in my android applicartion in run time, e.g. via Spinner.

I attempted to do subj in this way

DisplayMetrics dm = res.getDisplayMetrics();
Configuration conf = res.getConfiguration();
conf.locale = new Locale(language_code.toLowerCase(),
coutry_code.toUpperCase());
res.updateConfiguration(conf, dm);

but all changes apply only after restarting app Could anyone help me?

A: 

Well in the localization guide it automatically updated... and when I use spinners in my application it updates correctlly.. you have the spinner class set up at the bottom of your class right? or simply in the choices of your spinner, have it restart your intent like:

//spinner class start...
if(selected.equals("english") //given selected is a string returned by Spinner
{
   //normal spinner content you have goes here, then
   //for example, finish method, then restart with an intent
   finish()
   Intent myIntent = new Intent(main.this,main.class);
   main.this.startActivity(myIntent);
}
 //or..
if(selected.equals("french"){ // continued.. 
   refresh();
}

//given that refresh();
public void refresh(){
   finish()
   Intent myIntent = new Intent(main.this,main.class);
   main.this.startActivity(myIntent);
}
Samuel
Thanks, Sam!Maybe you can answer how to get resource string from certain locale?
John Wein