2012-10-17 183 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