0

I am developing an application which the user can select a language and It will show a message lets say for example "Hello" in a different language.

I have created a spinner.The user will select whatever language he/she wants to translate "Hello".

Here is my code on selecting items on the spinner. I dont know what to do next. How can I get the values from the folder values-es(Spanish), values-fi(Finnish) and so on.

public void onItemSelected(AdapterView<?> parent, View view, int pos,
        long id) {
    int position = parent.getSelectedItemPosition();
    switch (position) {
    case 0: // English

        break;
    case 1:// Spanish
                     //Display the value on  values-es/strings.xml
        break;
    case 2:// Finnish
                     //Display the value on  values-fi/strings.xml
        break;
    case 3:// French
                     //Display the value on  values-fr/strings.xml
        break;
    case 4:// Protuguese
                     //Display the value on  values-pt/strings.xml
        break;
    default:
        break;
    }
Mat
  • 202,337
  • 40
  • 393
  • 406
xknozi
  • 1,335
  • 3
  • 12
  • 20

1 Answers1

1

Use the following code

Locale locale2 = new Locale("fr"); 
Locale.setDefault(locale2);
Configuration config2 = new Configuration();
config2.locale = locale2;
getBaseContext().getResources().updateConfiguration(config2,       context.getResources().getDisplayMetrics());

 /** Update activity or restart application in order to update resources.**/
Hassan Jawed
  • 1,650
  • 1
  • 12
  • 19