how to show data in listview from web service in android
<p>my webservice return a data in the format</p>

<p>

 ab 
 cdef 


i have to show to this return data in listview here is my welcome.xml in which i have to display data</p>

<p><strong>welcome.xml</strong></p>

<pre><code>  &lt;?xml version="1.0" encoding="utf-8" ?&gt; 
- &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"&gt;
  &lt;ImageView android:id="@+id/welcome" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/main" android:layout_gravity="center_horizontal" /&gt; 
  - 
- &lt;RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="10dip" android:id="@+id/Relative01"&gt;
  &lt;ListView android:id="@+id/lvevent" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_below="@+id/welcome" android:background="@drawable/wel_bg" android:layout_marginBottom="50dip" /&gt; 
  &lt;/RelativeLayout&gt;
- &lt;TableLayout android:layout_height="fill_parent" android:layout_width="fill_parent" android:layout_below="@+id/Relative01"&gt;
- &lt;TableRow&gt;
  &lt;Button android:id="@+id/btn_index" android:layout_height="wrap_content" android:layout_width="wrap_content" android:background="@drawable/cap_button" android:paddingRight="15dip" android:layout_marginRight="50dip" /&gt; 
  &lt;Button android:id="@+id/btn_event" android:layout_height="wrap_content" android:layout_width="wrap_content" android:background="@drawable/button" android:layout_toRightOf="@+id/btn_index" android:paddingLeft="25dip" android:layout_marginLeft="30dip" /&gt; 
  &lt;/TableRow&gt;
  &lt;/TableLayout&gt;
  &lt;/LinearLayout&gt;
</code></pre>

<p>how can i show data in listview. </p>

<p>following code i am using for parser:</p>

<p>MYXMLHandler.java :</p>

<pre><code>package org.parsing;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;



public class MyXMLHandler extends DefaultHandler{
 Boolean currentElement = false;
 String currentValue = null;
 public static SitesList sitesList = null;

 public static SitesList getSitesList() {
  return sitesList;
 }

 public static void setSitesList(SitesList sitesList) {
  MyXMLHandler.sitesList = sitesList;
 }

 /** Called when tag starts ( ex:- &lt;name&gt;AndroidPeople&lt;/name&gt; 
  * -- &lt;name&gt; )*/
 @Override
 public void startElement(String uri, String localName, String qName,
   Attributes attributes) throws SAXException {

  currentElement = true;

  if (localName.equals("content"))
  {
   /** Start */ 
   sitesList = new SitesList();
  } /*else if (localName.equals("website")) {
   *//** Get attribute value *//*
   String attr = attributes.getValue("category");
   sitesList.setCategory(attr);
  }*/

 }

 /** Called when tag closing ( ex:- &lt;name&gt;AndroidPeople&lt;/name&gt; 
  * -- &lt;/name&gt; )*/
 @Override
 public void endElement(String uri, String localName, String qName)
   throws SAXException {

  currentElement = false;

  /** set value */ 
  if (localName.equalsIgnoreCase("title"))
   sitesList.setTitle(currentValue);
  else if (localName.equalsIgnoreCase("description"))
   sitesList.setDescription(currentValue);

 }

 /** Called to get tag characters ( ex:- &lt;name&gt;AndroidPeople&lt;/name&gt; 
  * -- to get AndroidPeople Character ) */
 public void characters(char[] ch, int start, int length)
   throws SAXException {

  if (currentElement) {
   currentValue = new String(ch, start, length);
   currentElement = false;
  }

 }


}
</code></pre>

<p>SitesList.java:</p>

<pre><code>package org.parsing;

import java.util.ArrayList;

public class SitesList {

 /** Variables */
 private ArrayList&lt;String&gt; title = new ArrayList&lt;String&gt;();
 private ArrayList&lt;String&gt; description = new ArrayList&lt;String&gt;();
 //private ArrayList&lt;String&gt; category = new ArrayList&lt;String&gt;();


 /** In Setter method default it will return arraylist 
  *  change that to add  */

 public ArrayList&lt;String&gt; getTitle() {
  return title;
 }

 public void setTitle(String title) {
  this.title.add(title);
 }

 public ArrayList&lt;String&gt; getDescription() {
  return description;
 }

 public void setDescription(String description) {
  this.description.add(description);
 }

 /*public ArrayList&lt;String&gt; getCategory() {
  return category;
 }

 public void setCategory(String category) {
  this.category.add(category);
 }
*/
}
</code></pre>

<p>XMLParsingExample.java:</p>

<pre><code>package org.parsing;

import java.net.URL;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;


import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.TextView;

public class XMLParsingExample extends Activity {
 /** Create Object For SiteList Class */
 SitesList sitesList = null;

 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);

  /** Create a new layout to display the view */
  LinearLayout layout = new LinearLayout(this);
  layout.setOrientation(1);

  /** Create a new textview array to display the results */
  TextView title[];
  TextView description[];
  //TextView category[];

  try {

   /** Handling XML */
   SAXParserFactory spf = SAXParserFactory.newInstance();
   SAXParser sp = spf.newSAXParser();
   XMLReader xr = sp.getXMLReader();

   /** Send URL to parse XML Tags */
   URL sourceUrl = new URL(
     "http://208.109.97.179:1010/webservices/newsevents.php");

   /** Create handler to handle XML Tags ( extends DefaultHandler ) */
   MyXMLHandler myXMLHandler = new MyXMLHandler();
   xr.setContentHandler((ContentHandler) myXMLHandler);
   xr.parse(new InputSource(sourceUrl.openStream()));

  } catch (Exception e) {
   System.out.println("XML Pasing Excpetion = " + e);
  }

  /** Get result from MyXMLHandler SitlesList Object */
  sitesList = MyXMLHandler.sitesList;

  /** Assign textview array lenght by arraylist size */
  title = new TextView[sitesList.getTitle().size()];
  description = new TextView[sitesList.getDescription().size()];
  //category = new TextView[sitesList.getName().size()];

  /** Set the result text in textview and add it to layout */
  for (int i = 0; i &lt; sitesList.getTitle().size(); i++) {
   title[i] = new TextView(this);
   title[i].setText("Title = "+sitesList.getTitle().get(i));
   description[i] = new TextView(this);
   description[i].setText("Website = "+sitesList.getDescription().get(i));
   //category[i] = new TextView(this);
   //category[i].setText("Website Category = "+sitesList.getCategory().get(i));

   layout.addView(title[i]);
   layout.addView(description[i]);
   //layout.addView(category[i]);
  }

  /** Set the layout view to display */
  setContentView(layout);

 }

}
</code></pre>

<p>after checking my code tell me where i am wrong and tell the correct answer.</p>
