Android 数组中的语言翻译

Android 数组中的语言翻译,android,internationalization,Android,Internationalization,我有几个阵列,其中一个带有微调器,但我怀疑这是否重要 无论如何,我需要把这些翻译成其他语言。我的程序是一个android应用程序,我在大部分应用程序中都使用了@string,但是数组让我很恼火 这是微调器阵列 private static final String[]paths = {"Click to select", "One", "Two", "Three"}; 我究竟如何翻译数组中的文本?我在其他网站上尝试过几种方法,但都未能成功构建。只需在运行时解析字符串,然后将解析后的字符

我有几个阵列,其中一个带有微调器,但我怀疑这是否重要

无论如何,我需要把这些翻译成其他语言。我的程序是一个android应用程序,我在大部分应用程序中都使用了@string,但是数组让我很恼火

这是微调器阵列

    private static final String[]paths = {"Click to select", "One", "Two", "Three"};

我究竟如何翻译数组中的文本?我在其他网站上尝试过几种方法,但都未能成功构建。

只需在运行时解析字符串,然后将解析后的字符串放入数组中即可

String s1 = context.getResources().getString(R.string.s1);
String s2 = context.getResources().getString(R.string.s2);
String s3 = context.getResources().getString(R.string.s3);
String s4 = context.getResources().getString(R.string.s4);

String[] paths = { s1, s2, s3, s4 };
在字符串资源文件中:

 <string name="s1">Click to select</string>
 <string name="s2">One</string>
 <string name="s3">Two</string>
 <string name="s4">Three</string>
单击以选择
一个
两个
三

我终于解决了这个问题

String.xml

    <string-array name="paths_array">
         <item>Click to select</item>
         <item>One</item>
         <item>Two</item>
         <item>Three</item>
    </string-array>
超级简单,我在谷歌的Android资源网站上找到了它,我以为我试过一次,但在查看XML条目后,我意识到它与我以前试过的完全不同

现在编译和运行非常完美,最终可以转换微调器


感谢所有的帮助,因为它引导我走上了正确的道路。

从来没有遇到过这个。。。。我将尝试一下,看看会发生什么。大量的剪切和粘贴将会发生,但这不起作用。不断抱怨id1,2,3,4。表示“无法解析符号id1”,我已更正了答案。我输入了错误的字符串ID。我输入了“R.string.id1”,但它应该是“R.string.s1”,等等。进行了这些更改,应用程序崩溃。如果我恢复到常规数组,不会崩溃。你有崩溃的logcat输出吗?你可以将所有单独的字符串放在strings.xml文件中,并在数组中引用它们。例如,一个,然后在数组中:@string/One
    String[] paths;

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.yourlayout);

    paths = getResources().getStringArray(R.array.paths_array);
    }