ListView和R字符串目录

我创建了一个项目(即android应用),并使用了自定义ListView,每列使用三个TextView UI。但是,该应用程序还设计为使用strings.xml文件支持多语言(至少三种),以便在用户选择时获取所选语言。因此,这里的情况是,我必须用Java编写ListView String [] example {"a","b","c"}。我试图做这样的事情String [] example {R.string.a,R.string. b,R.string. c},但是编译器说Error " illegal array "

现在我的问题是:是否可以将String [] { }的{​​{1}}引用到ListView文件中。

预先感谢您,我感谢任何示例代码或链接。

cen12 回答:ListView和R字符串目录

如果数组的元素是常量,则可以在strings.xml中创建字符串数组,并在代码中访问该数组。

将以下内容放入 strings.xml

<string-array name="example">
        <item>a</item>
        <item>b</item>
        <item>c</item>
</string-array>

以以下代码访问此数组:

String examples[] = getResources().getStringArray(R.array.example);
,

您不能使用对counta :: [Char] -> Int counta [] = [] counta (x:xs) = let i = 0 if isDigit(x) then i = i + 1 counta xs else counta xs 数组的直接引用,必须通过String获取String resource的值

像这样

getString()
本文链接:https://www.f2er.com/3153864.html

大家都在问