请看这张图片,我想以这种形式显示我的短信,请帮助我
这是 xml 文件:
<smses count="2">
<sms
protocol="0"
address="123"
date="1356069180000"
type="1"
subject="null"
body="nDGd0Or7LQCajC+GSkQFDw=="
toa="null"
sc_toa="null"
service_center="null"
read="0"
status="0"
locked="0"
date_sent="0"
readable_date="Dec 21, 2012 5:53:00 AM"
contact_name="(Unknown)"/>
<sms
protocol="0"
address="123"
date="1356069181021"
type="1"
subject="null"
body="hw r u"
toa="null"
sc_toa="null"
service_center="null"
read="0"
status="-1"
locked="0"
date_sent="1356069180000"
readable_date="Dec 21, 2012 5:53:01 AM"
contact_name="(Unknown)"/>
</smses>
.
try{
File fXmlFile = new File(/mnt/sdcard/myxmlfile.xml);
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(fXmlFile);
doc.getDocumentElement().normalize();
NodeList nl = doc.getElementsByTagName("sms");
pDialog.setMax(nl.getLength());
for (int i = 0; i < nl.getLength(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
Node nNode = nl.item(i);
Element e = (Element) nNode;
String number= getNodeAttributeByTagName(nNode, "address");
map.put(KEY_ADDRESS,number);
map.put("body",getNodeAttributeByTagName(nNode, "body"));
map.put(KEY_CONTACT, getContactDisplayNameByNumber(number));
menuItems.add(map);
String y = String.valueOf(i);
publishProgress(y);
}
}catch(Exception e){
e.printStackTrace();
}
显示在列表中
ListAdapter adapter = new SimpleAdapter(showlist.this, menuItems,
R.layout.list_item_albums,
new String[] { KEY_CONTACT, "body", KEY_ADDRESS }, new int[] {
R.id.contact, R.id.body, R.id.address });
list1.setAdapter(adapter);
}