如何提取字符串数组中的name属性?字符串、组中、属性、name

2023-09-12 07:52:02 作者:一尺江山

您好我建立一个测验的应用程序。 我有以下的(值/)question.xml

Hi I build a quiz application. I have the following (values/)question.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="question">
<item name="correct">A</item>
<item name="wrong">B</item>
<item name="wrong">C</item>
<item name="wrong">D</item>
</string-array>
</resources>

我想有四个可能的答案的问题,但是当我取回我的答案在Java中..我不知道哪个答案是正确的。所以,我决定使用该项目的标签名称属性传递的正确或错误的答案的值。 反正是有获取名称与标记值?

I would like to have a question with four possible answers but when i retrieve my answers in Java.. I don't know which answer is correct. So I decided to use name attribute in the item tags to pass a value of 'correct' or 'wrong' answer. Is there anyway to get the name along with the tag value?

因为当我使用的String []测试= res.getStringArray(R.array.question);我只能得到每件商品的价值在我的数组。

because when i use String[] test = res.getStringArray(R.array.question); I can only get the value of each item in my array.

或因为这是我在Android的第1次。有没有其他合适的方法来做到这一点?

or because this is my 1st time in Android. is there other suitable approach to do this?

感谢

推荐答案

您需要使用处理程序来解析XML。 得到的属性值,code是:

You need to use Handler to parse the xml. to get attribute value, code is :

attributes.getValue("name")

尝试这些链接以供参考: 第一并 第二

Try these links for reference: first and second

 
精彩推荐
图片推荐