开发者

problem in parsing images to a grid view in android

in my app when i hit an url it returns back an xml file from that file i am getting some images. By sax parser i am getting the no of image and the url where the images are been stored. Now i want to show all the images in a grid view. But for me only the last image in the xml file is alone viewed in the grid format. Following is my code

SAXParserFactory spf = SAXParserFactory.newInstance();
            SAXParser sp = spf.newSAXParser();
            XMLReader xr = sp.getXMLReader();
            InputSource is = new InputSource();
            is.setCharacterStream(new StringReader(UserManual.IMGD开发者_高级运维ATA));
            xr.setContentHandler(forlistmyhandler);
            xr.parse(is);

sitesList = forlistmyhandler.getSearch();
        searchdata = forlistmyhandler.getSearchdata();

Q = sitesList.getSearchdata().size();
for(int k=0;k<sitesList.getSearchdata().size();k++)
        {
            Log.e("MyXMLHandler", "000000000 Created");
            Searchdata chap = sitesList.getSearchdata().get(k);
            id = chap.getId();
            HashMap<String, Object> map = new HashMap<String, Object>(); 
            map.put("ID", id );
            grid.setAdapter(new ImageAdapter(this));
            Log.e("id tag",""+id);
        }

public class ImageAdapter extends BaseAdapter 
    {
        private Context myContext;

        private String[] myRemoteImages = {id};

        public ImageAdapter(Context c) 
        { 
            this.myContext = c; 
        }
        }

Please help me to solve my problem


In these case instead of using Hashmap try using String[]. Add the values in ArrayList and then convert to String Array.

Pass String[] to Adapter and load images and display.

In these for Loop code :

ArrayList<String> images = new ArrayList<String>();
String[] VALUE_images;

for(int k=0;k<sitesList.getSearchdata().size();k++)
    {
        Log.e("MyXMLHandler", "000000000 Created");
        Searchdata chap = sitesList.getSearchdata().get(k);
        id = chap.getId();
        images.add(id ); 
    } 
   int img=-1;
   VALUE_images= new String[images.size()];
   Iterator<String> it = images.iterator();
   while (it.hasNext()) {
      img++;
      VALUE_images[dealid] = it.next().toString();
   }
   grid.setAdapter(new ImageAdapter(this,VALUE_images));


public class ImageAdapter extends BaseAdapter 
{
    private Context myContext;

    private String[] myRemoteImages = {id};

    public ImageAdapter(Context c,String[] value1) 
    { 
        this.myContext = c; 
        VAL1 = value1;
    }

    // as usual code follows 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜