Monday, 7 July 2014

parse xml file from url and display it in android listview



IN my app i need to parse the xml file from a url and need to display it in listview. I get the xml string succesfully from th url but the problem is that if i try to display it in listview, nothing is shown, even the listview layout is not showing. any help in the this will be thankful..


code



ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String,String>>();

XMLParser parser = new XMLParser();
String xml = parser.getXmlFromUrl(URL); // getting XML

Document doc = parser.getDomElement(xml); // getting DOM element

NodeList nl = doc.getElementsByTagName(title);
// looping through all item nodes <item>

for (int i = 1; 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(time, parser.getValue(e, time));
map.put(description, parser.getValue(e, description));
map.put(name, parser.getValue(e, name));
// adding HashList to ArrayList
menuItems.add(map);

}

No comments:

Post a Comment