我正在从web xml文件和图像中读取数据。我把图像作为Bitmap bmImg,我把它放在Hashmap中。但我确实知道如何修改我的simpleAdapter函数以在imageView中显示该图像。 我被困在这里,我正在做研究项目。有什么建议吗?
这是代码:
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);
答案 0 :(得分:0)
现在为时已晚,但如果其他人遇到同样的问题,我在那里给出的答案应该可以解决你遇到的问题: