2012-10-17 182 views
0

我正在開發一個應用程序,用戶可以選擇一種語言,它會顯示一個消息讓我們說,例如「你好」用不同的語言。選擇語言和翻譯

我已經創建了一個spinner.the用戶將選擇他/她想翻譯「你好」的任何語言。

這是我在代碼中選擇項目的代碼。我不知道下一步該怎麼做。我如何從文件夾值-ES(西班牙語),值-Fi(芬蘭語)等等獲取值。

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; 
    } 

回答

1

使用下面的代碼

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.**/ 
+0

嘿感謝。與這一個相同的方法http://stackoverflow.com/questions/2900023/change-language-programatically-in-android。 – jeponkz

+0

這沒有翻譯當前片段 – TeodorKolev