我在res/values
中有一个带有字符串数组的XML文件,其项目包含简单的HTML标记,例如:
<resources>
<string-array name="frases31">
<item>They <u>were not</u> before.</item>
<item>I don\'t think <u>he</u> is.</item>
...
我将这些加载到String[]
数组中:
Resources res = mContext.getResources();
exercise.setSentences(res.getStringArray(R.array.frases31));
问题是变量String[]
中的exercise
数组,其名为sentences
,仅包含字符串,HTML标记(<u>
和</u>
)已经消失了。
我应该将调用res.getStringArray(R.array.frases31)
的结果存储在特殊变量中吗?
我有一个索引,我会以编程方式将sentences[i]
放入TextView
。
答案 0 :(得分:5)
您需要编辑XML才能实现此目的。您可以使用CDATA包装项目以保留标记:
<item><![CDATA[They <u>were not</u> before.]]></item>
<item><![CDATA[I don\'t think <u>he</u> is.]]></item>
或单独转义每个标记字符:
<item>They <u>were not</u> before.</item>
<item>I don\'t think <u>he</u> is.</item>