我想从URL获取图像,然后将其添加到列表视图。我可以成功获取图像,但我很努力将其添加到列表视图。从JSON 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
@mango我dint得到任何错误。我可以在Imageview中获取图像,但不能在listview中获取图像。 Y? –