如何提取字符串数组中的name属性? [英] how to extract the name attribute from string array?
问题描述
您好我建立一个测验的应用程序。 我有以下的(值/)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
这篇关于如何提取字符串数组中的name属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!