Click here to Skip to main content
15,893,588 members
Articles / Mobile Apps / Android

Customized Android ListView with Image and Text

Rate me:
Please Sign up or sign in to vote.
4.64/5 (43 votes)
17 Jan 2013CPOL6 min read 399.1K   26K   96  
Creating a customized ListView in Android
package vatsag.samples.weatherdisplay;

import java.util.ArrayList;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

/*
 * Default Notification handler class for receiving ContentHandler
 * events raised by the SAX Parser
 * 
 * */
public class XParser extends DefaultHandler {

	ArrayList<String> idlist = new ArrayList<String>();
	ArrayList<String> citylist = new ArrayList<String>();
	ArrayList<String> condilist = new ArrayList<String>();
	ArrayList<String> templist = new ArrayList<String>();
	ArrayList<String> speedlist = new ArrayList<String>();
	ArrayList<String> iconlist = new ArrayList<String>();
	
	//temp variable to store the data chunk read while parsing 
	private String tempStore	=	null;
		
	public XParser() {
		// TODO Auto-generated constructor stub
	}
	
	/*
	 * Clears the tempStore variable on every start of the element
	 * notification
	 * 
	 * */
	public void startElement (String uri, String localName, String qName,
			   Attributes attributes) throws SAXException {
	
		super.startElement(uri, localName, qName, attributes);
		
		if (localName.equalsIgnoreCase("id")) {
			tempStore = "";
		} else if (localName.equalsIgnoreCase("city")) {
			tempStore = "";
		} 
		else if (localName.equalsIgnoreCase("tempc")) {
			tempStore = "";
		}
		else if (localName.equalsIgnoreCase("condition")) {
			tempStore = "";
		}
		else if (localName.equalsIgnoreCase("windspeed")) {
			tempStore = "";
		}
		else if (localName.equalsIgnoreCase("icon")) {
			tempStore = "";
		}
		else {
			tempStore = "";
		}
	}
	
	/*
	 * updates the value of the tempStore variable into
	 * corresponding list on receiving end of the element
	 * notification
	 * */
	public void endElement(String uri, String localName, String qName)
			throws SAXException {
		super.endElement(uri, localName, qName);
		
		if (localName.equalsIgnoreCase("id")) {
			idlist.add(tempStore);
		} 
		else if (localName.equalsIgnoreCase("city")) {
			citylist.add(tempStore);
		}
		else if (localName.equalsIgnoreCase("tempc")) {
			templist.add(tempStore);
		}
		else if (localName.equalsIgnoreCase("condition")) {
			condilist.add(tempStore);
		}
		else if (localName.equalsIgnoreCase("windspeed")) {
			speedlist.add(tempStore);
		}
		else if (localName.equalsIgnoreCase("icon")) {
			iconlist.add(tempStore);
		}
		
		tempStore = "";
	}
	
	/*
	 * adds the incoming data chunk of character data to the 
	 * temp data variable - tempStore
	 * 
	 * */
	public void characters(char[] ch, int start, int length)
			throws SAXException {
		super.characters(ch, start, length);
		tempStore += new String(ch, start, length);
	}

}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer Honeywell International
India India
Software Developer, Cinephile, Dromomaniac, Animal lover, Self proclaimed Photographer not necessarily in the same order.

Comments and Discussions