我正在从 web xml 文件和图像中读取数据,也从 web 读取数据。我将图像作为位图 bmImg 并将其放入 Hashmap 中。但我确实知道如何修改我的 simpleAdapter 函数以在 imageView 中显示该图像。我被困在这里,我正在做学习项目。有什么建议么?
这是代码:
NodeList 节点 = 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);