我使用以下代码获取 nameList
我认为nameList的内容将是Inbox,Sent,Outbox和Draft,这是我的愿望。
但实际上nameList的内容是@string/Inbox、@string/Sent、@string/Outbox和@string/Draft。为什么?谢谢!
private void InitVar(){
ArrayList nameList=new ArrayList<String>();
ArrayList valueList=new ArrayList<String>();
ParXML(this, nameList, valueList);
}
public static void ParXML(Context context, List<String> nameList,List<String> valueList) {
XmlResourceParser xrp = context.getResources().getXml(R.xml.msgfolder);
try {
while (xrp.getEventType() != XmlResourceParser.END_DOCUMENT) {
if (xrp.getEventType() == XmlResourceParser.START_TAG) {
String tagName = xrp.getName();
if (tagName.equals("item")) {
nameList.add(xrp.getAttributeValue(null, "name"));
valueList.add(xrp.getAttributeValue(null, "value"));
}
}
xrp.next();
}
} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
值\strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="Inbox">Inbox</string>
<string name="Sent">Sent</string>
<string name="Outbox">Outbox</string>
<string name="Draft">Draft</string>
</resources>
xml\msgfolder.xml
<?xml version="1.0" encoding="utf-8"?>
<MsgHandle>
<item name="@string/Inbox" value="content://sms/inbox"></item>
<item name="@string/Sent" value="content://sms/sent"></item>
<item name="@string/Outbox" value="content://sms/outbox"></item>
<item name="@string/Draft" value="content://sms/draft"></item>
</MsgHandle>