serialization issue of images data based on XML
<p>In my code images data is not serialize with text data in display output. </p>

<p>I want this type of output:-</p>

<p><img src="http://i.stack.imgur.com/lgwIS.jpg" alt="enter image description here"></p>

<p>But getting this type of output (images are not serialize with title text) :</p>

<p><img src="http://i.stack.imgur.com/SR07x.jpg" alt="enter image description here"></p>

<p>This is my xml in which i'm not getting all the elements regularly like </p>

<pre><code>&lt;smallimage&gt;
</code></pre>

<p>.</p>

<pre><code>&lt;posts&gt;
          &lt;page id="1"&gt;
                      &lt;title&gt;
                            &lt;![CDATA[ title text 1 ]]&gt;
                      &lt;/title&gt;

                      &lt;smallimage&gt;
                                 http://www.xyz.com/image1.jpg
                      &lt;/smallimage&gt;
          &lt;/page&gt;

          &lt;page id="2"&gt;
                      &lt;title&gt;
                            &lt;![CDATA[ title text 2 ]]&gt;
                      &lt;/title&gt;
          &lt;/page&gt;

          &lt;page id="3"&gt;
                      &lt;title&gt;
                            &lt;![CDATA[ title text 3 ]]&gt;
                      &lt;/title&gt;

                      &lt;smallimage&gt;
                                 http://www.xyz.com/image3.jpg
                      &lt;/smallimage&gt;
          &lt;/page&gt;

          &lt;page id="4"&gt;
                      &lt;title&gt;
                            &lt;![CDATA[ title text 4 ]]&gt;
                      &lt;/title&gt;

                      &lt;smallimage&gt;
                                 http://www.xyz.com/image4.jpg
                      &lt;/smallimage&gt;
          &lt;/page&gt;

          &lt;page id="5"&gt;
                      &lt;title&gt;
                            &lt;![CDATA[ title text 5 ]]&gt;
                      &lt;/title&gt;
          &lt;/page&gt;

          &lt;page id="6"&gt;
                      &lt;title&gt;
                            &lt;![CDATA[ title text 6 ]]&gt;
                      &lt;/title&gt;

                      &lt;smallimage&gt;
                                 http://www.xyz.com/iamge6.jpg
                      &lt;/smallimage&gt;
          &lt;/page&gt;
  &lt;/posts&gt;
</code></pre>

<p>I'm displaying this on the list view as shown in my dummy images:</p>

<p>mainActivity.java</p>

<pre><code>public class mainActivity extends Activity {
    /** Called when the activity is first created. */

    static final String URL = "http://www.abc.com/api.php?page_id=1";

    ItemList itemList;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);


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

        System.out.println("This XML is ========&gt;"+XML);

       try
       {
           SAXParserFactory spf = SAXParserFactory.newInstance();
           SAXParser sp = spf.newSAXParser();
           XMLReader xr = sp.getXMLReader();

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

           ByteArrayInputStream is = new ByteArrayInputStream(XML.getBytes());
           xr.parse(new InputSource(is));
      }
      catch(Exception e)
      {

      }

      itemList = MyXMLHandler.itemList;

      ArrayList&lt;String&gt; listItem= itemList.getTitle();
      ArrayList&lt;String&gt; listManu = itemList.getSmallimages();


      System.out.println("(ListItem)=======&gt;"+listItem);
      System.out.println("(ListManu)=======&gt;"+listManu);

    //  String ar[];
      Object obj[]=listManu.toArray();
      String[] stringArray=Arrays.asList(obj).toArray(new String[obj.length]);


     ListView lview = (ListView) findViewById(R.id.listview1);
     myAdapter adapter = new myAdapter(this, listItem, stringArray);
     lview.setAdapter(adapter);
</code></pre>

<p>XMLParser.java</p>

<pre><code>public class XMLParser {

    // constructor
    public XMLParser() {

    }

    /**
     * Getting XML from URL making HTTP request
     * @param url string
     * */
    public String getXmlFromUrl(String url) {
        String xml = null;

        try {
            // defaultHttpClient
            DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost(url);

            HttpResponse httpResponse = httpClient.execute(httpPost);
            HttpEntity httpEntity = httpResponse.getEntity();
            xml = EntityUtils.toString(httpEntity);

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        // return XML
        return xml;
    }
}
</code></pre>

<p>ItemList.java</p>

<pre><code>public class ItemList 
{
    ArrayList&lt;String&gt; title = new ArrayList&lt;String&gt;();
    ArrayList&lt;String&gt; smallimage = new ArrayList&lt;String&gt;();

    public ArrayList&lt;String&gt; getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title.add(title);
    }
    public ArrayList&lt;String&gt; getSmallimages() {
        return smallimage;
    }
    public void setSmallimages(String smallimage) {
        this.smallimage.add(smallimage);
    }

    public Object get(int position) {

        return title.get(position);
        // TODO Auto-generated method stub
    //  return null;
    }
}
</code></pre>

<p>MyXMLHandler.java</p>

<pre><code>public class MyXMLHandler extends DefaultHandler
{
    public static ItemList itemList;
    public boolean current = false;
    public String currentValue = null;

    private StringBuffer buffer;

    @Override
    public void startElement(String uri, String localName, String qName,
            Attributes attributes) throws SAXException {
        // TODO Auto-generated method stub

        buffer = new StringBuffer();

        current = true;

        if (localName.equals("posts"))
        {
            /** Start */ 
            itemList = new ItemList();

        } 
    }

    @Override
    public void endElement(String uri, String localName, String qName)
            throws SAXException {
        // TODO Auto-generated method stub

        currentValue = buffer.toString();

        current = false;
        if(localName.equals("title"))
        {
            System.out.println("1");
            itemList.setTitle(currentValue);

        }
        else if(localName.equals("smallimage")) 
        {
            System.out.println("2");
            itemList.setSmallimages(currentValue);
        }
        else{   
            System.out.println("5");
             String a="http://a3.twimg.com/profile_images/670625317/aam-logo-v3-twitter.png";
                itemList.setSmallimages(a);
             }


            }       



    @Override
    public void characters(char[] ch, int start, int length)
            throws SAXException {
        // TODO Auto-generated method stub
        System.out.println("z");

        String readChars = new String(ch,start,length);
        if(buffer != null) buffer.append(readChars);

        java.lang.System.out.println("vk==============&gt;"+readChars);

    }
}
</code></pre>

<p>myAdapter.java</p>

<pre><code>public class myAdapter extends BaseAdapter 
{
    ArrayList&lt;String&gt; listTitle;
    String [] data;
    ImageLoader imageLoader;


    Activity activity;

    public myAdapter(Activity activity, ArrayList&lt;String&gt; listTitle, String[] d) {
        super();
        this.listTitle = listTitle;
        this.data = d;


        this.activity = activity;
        this.imageLoader = new ImageLoader(activity.getApplicationContext());
    }

    public int getCount() {
        // TODO Auto-generated method stub
        return listTitle.size();

    }

    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return null;
    }

    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return 0;
    }

    private class ViewHolder
    {
        TextView txtViewTitle;
        ImageView image;


    }

    public View getView(int position, View view, ViewGroup parent) {
        // TODO Auto-generated method stub

        ViewHolder title;
        LayoutInflater inflater = activity.getLayoutInflater();

        if(view==null)
        {
            view = inflater.inflate(R.layout.lview_row, null);
            title = new ViewHolder();

            title.txtViewTitle = (TextView) view.findViewById(R.id.txtItem);
            title.image = (ImageView) view.findViewById(R.id.list_image);

            view.setTag(title);
        }
        else
        {
            title = (ViewHolder) view.getTag();
        }

        title.txtViewTitle.setText(listTitle.get(position));


        imageLoader.DisplayImage(data[position], title.image);

        return view;
    }
}
</code></pre>

<p>This is my code which is getting all the things but images are not serialized with respective title text all the images are displayed of using "LazyList" example (imageLoader). Any one please suggest me the way to get the proper serialize images with the corresponding title text based on given XML.</p>

<p>Thanks in advanced.</p>
