Android版:适用于列表多维字符串数组 [英] Android: Using multi-dimensional string array for list

查看:100
本文介绍了Android版:适用于列表多维字符串数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Andr​​oid列表页/活动我有一个2文本域主而第1以上的对方,但是当它coems​​创造了它,我只看到文字的一个部分实例数组字符串。

In my android list page/activity I have a 2 text fields a main and subsection one above each other, but when it coems to creating the array string for it I only see examples with the one section of text.

 <resources>
    <string name="hello">Hello!</string>
 </resources>

要再创建什么,我想我会做一个if语句相匹配的标题那么如果这么加字幕,但我想拥有它,所以我可以读我的标题和副标题字符串类似如下:

To then create what I want I would do a if statement to match the title then if so add the subtitle, but I would like to have it so I can read my title and subtitle strings something like below:

  <resources>
      <string name="hello">
          <item>Hello!</item>
          <item>my subtitle </item>
      </string>
      <string name="hello">
          <item>Hello!</item>
          <item>my subtitle </item>
      </string>
  </resources>

但我不能找到如何阅读列表项等的例子,所以我并不需要做很长的,如果我的Java中的语句来匹配字幕的标题。

But I cannot find an example of how to read this to a list item etc, so I do not need to do a long if statement within my java to match the subtitle to the title.

非常感谢

推荐答案

我通常用分隔管道文|并显示,当把它分解。它有点难看,但它工作。

I usually delimit the text with a pipe | and split it when displaying. Its a bit ugly, but it works.

<item>item1|item2</item>

然后当我把它在getView(...)

then when I call it in getView(...)

String[] r = c.getResources().getStringArray(R.array.arraylist).split("\\|");

然后我有索引定义:

then I have defines for the index:

private final int VIEW_HEADING_TITLE = 0;
private final int VIEW_HEADING_SUB = 1;

这篇关于Android版:适用于列表多维字符串数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆