我有一个xml文件并从该文件中获取数据并将其保存在arraylist
中xml文件:
<head>33</head>
<link>http://hamrahtest.ir/testcenterv13.apk</link>
</group>
<group>
<head>355</head>
<link>http://hamrahtest.ir/testcenterv5555.apk</link>
</group>
protected void onPostExecute(Document doc) {
ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>();
NodeList nl = doc.getElementsByTagName(KEY_GROUPS);
// looping through all song nodes <song>
for (int i = 0; i < nl.getLength(); i++) {
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
Element e = (Element) nl.item(i);
// adding each child node to HashMap key => value
map.put(KEY_HEAD, parser.getValue(e, KEY_HEAD));
map.put(KEY_LINK, parser.getValue(e, KEY_LINK));
// adding HashList to ArrayList
songsList.add(map);
}
Log.d("tagname",songsList.get(1).get(KEY_HEAD).toString());
}
根据此代码我有一行:
private static final String[] CONTENT = new String[] {" page1","page2"};
我如何将KEY_HEAD valuse插入CONTENT而不是{“page1”,“page2”}?
答案 0 :(得分:0)
您可以使用HashMap
获取Set Set<String>
个密钥,使用toArray(T[] a)将Set<String>
转换为String[]
Set<String> keys = map.keySet();
String[] CONTENT = new String[keys .size()];
keys.toArray(CONTENT);