开发者

want to show image after getting from web using SimpleAdapter

开发者 https://www.devze.com 2023-02-27 03:27 出处:网络
I am reading data from web xml file and image also from web. I get the image as Bitmap bmImg and I have putted it in Hashmap. But I do know how to modify my simpleAdapter function to show that image i

I am reading data from web xml file and image also from web. I get the image as Bitmap bmImg and I have putted it in Hashmap. But I do know how to modify my simpleAdapter function to show that image in the imageView. I am stuck up here and I am doing study project. Any suggestions?

This is the code:

NodeList nodes = doc.getElementsByTagName("product"); for (int i = 0; i < nodes.getLength(); i++) {

    HashMap<String, Object> map = new HashMap<String, Object>();    

        Element e = (Element)nodes.item(i);
          Bitmap bmImg = null;


           try {

               DefaultHttpClient httpClient = new DefaultHttpClient();
               HttpPost httpPost = new HttpPost("http://licrp.dnsalias.net:8000/iteam/images/" + GetXML.getValue(e, "ImagePath"));
               HttpResponse httpResponse = httpClient.execute(httpPost);
               HttpEntity httpEntity = httpResponse.getEntity();
               BufferedHttpEntity b_entity = new BufferedHttpEntity(httpEntity);
               InputStream input = b_entity.getContent();

               bmImg = BitmapFactory.decodeStream(input);

            } catch (MalformedURLException e1) {

            } catch (IOException e1) {

            } 

        map.put("id", GetXML.getValue(e, "id"));
        //map.put("ProductName", "Product Name:" + GetXML.getValue(e, "ProductName")); Example
        map.put("ProductName", GetXML.getValue(e, "ProductName"));
        map.put("Desc",  GetXML.getValue(e, "Desc"));
        map.put("Price", GetXML.getValue(e, "Price"));
        map.put("ImagePath", bmImg);
        mylist.add(map);            
    }       

    SimpleAdapter adapter = new SimpleAdapter(this, mylist , R.layout.lbsdetailviewmain, 
                    new String[] { "ProductName", "Desc","Price","ImagePath" }开发者_运维问答, 
                    new int[] { R.id.product_name, R.id.desc , R.id.price,R.id.image1});
    setListAdapter(adapter);
    final ListView lv = getListView();
    lv.setTextFilterEnabled(true);  


It's too late, but if someone else is stuck with the same problem, the answer I gave there should solve the problem you had :

Displaying bitmap image in imageview by simple adapter

0

精彩评论

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