【发布时间】:2012-12-04 07:38:06
【问题描述】:
我正在尝试从 URL 获取图像,然后将其添加到列表视图。我可以成功获取图像,但我正在努力将其添加到列表视图中。
我试过这种方式:
ListView lv = (ListView) findViewById(R.id.list);
try {
URL url = new URL("http://devcms.barcodo.com/Images/ProductImages/ThumbnailImages100/EG-BIRT-ST-JA_th.jpg");
HttpGet httpRequest = null;
httpRequest = new HttpGet(url.toURI());
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = (HttpResponse) httpclient.execute(httpRequest);
HttpEntity entity = response.getEntity();
BufferedHttpEntity b_entity = new BufferedHttpEntity(entity);
InputStream input = b_entity.getContent();
Bitmap bitmap = BitmapFactory.decodeStream(input);
HashMap<String, Object> docList = new HashMap<String, Object>();
docList.put("IMAGE", bitmap);
ArrayList<HashMap<String, Object>> al = new ArrayList<HashMap<String, Object>>();
al.add(docList);
simpleAdapter = new SimpleAdapter(this, al, R.layout.list_item,new String[] { "IMAGE" }, new int[] { R.id.image});
lv.setAdapter(simpleAdapter);
注意:我可以将其放入 ImageView 中,但想提取到列表视图中。
【问题讨论】:
-
您是否收到错误消息?我认为该实现仅适用于将文本应用于文本视图。您的适配器可能认为您的图像是文本。您可能需要制作一个自定义适配器。
-
@mango 我不会得到任何错误。我可以在 Imageview 中获取图像,但不能在 listview 中获取。是吗?
标签: android json bitmap android-listview