I am trying to get image from URL then add it to a listview. I can successfully get the image, but I’m struggling with adding it to the listview.
I have tried this way:
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);
Note: I am able to put it into an ImageView, but want to fetch into a listview.
try the following: