Java 在列表视图数组上使用 strings.xml 项目

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18304404/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 00:18:52  来源:igfitidea点击:

Using strings.xml items on a listview array

javaandroidandroid-listviewandroid-arrayadapter

提问by Genis

I'm coding an Android app with android studio. I'm displaying a ListView who gets its content from a String Array. I want to use the strings.xml items in the array of the listview, but I can't. Please help me. I'm doing this for the first item of the array:

我正在使用 android studio 编写一个 Android 应用程序。我正在显示一个从字符串数组中获取其内容的 ListView。我想在列表视图的数组中使用strings.xml 项,但我不能。请帮我。我正在为数组的第一项执行此操作:

 public final String palanca= (getResources().getString(R.string.palanca));
private String [] formls = {palanca,"@string/uMR","@string/new1","@string/new2","@string/new3"};

Thank You!

谢谢你!

采纳答案by es0329

Create a string array resource in your strings.xml.

在您的 strings.xml 中创建一个字符串数组资源。

<string-array name="colors">
    <item>Red</item>
    <item>Green</item>
    <item>Blue</item>
</string-array>

Use your string array from your Java just like you would any other string resource.

就像使用任何其他字符串资源一样,使用 Java 中的字符串数组。

private String[] colors = getResources().getStringArray(R.array.colors);