To display images in a ListView?

La download image use:


public static Bitmap downloadImage(String iUrl) {
 Bitmap bitmap = null;
 HttpURLConnection conn = null;
 Buf_stream BufferedInputStream = null;
 try {
 Log.v(TAG, "Starting loading image by URL:" + iUrl);
 conn = (HttpURLConnection) new URL(iUrl).openConnection();
 conn.setRequestProperty("Connection", "Keep-Alive");
 buf_stream = new BufferedInputStream(conn.getInputStream(), 8192);
 bitmap = BitmapFactory.decodeStream(buf_stream);
 buf_stream = null;
 conn = null;
 } catch (MalformedURLException ex) {
 Log.e(TAG, "failed parsing the Url was:" + iUrl);
 } catch (IOException ex) {
 Log.d(TAG, iUrl + "does not exists");
 } catch (OutOfMemoryError e) {
 Log.w(TAG, "Out of memory!!!");
 return null;
 } finally {
 if ( buf_stream != null )
 try { buf_stream.close(); } catch (IOException ex) {}
 if ( conn != null )
 return bitmap;

To update the ListView

 JSONObject jsonResponse = new JSONObject(response.toString());
 JsonMainNode JSONArray = jsonResponse.getJSONArray("items");
 //JSONArray Data = jsonResponse.getJSONArray("snippet");

 for(int i = 0; i<jsonmainnode.length();i++){ jsonobject jsonchildnode="jsonMainNode.getJSONObject(i);" string name="jsonChildNode.optString("kind");" number="jsonChildNode.optString("etag");" item="jsonMainNode.getJSONObject(i);" snippet="item.getJSONObject("snippet");" title="snippet.getString("title");" channeltitle="snippet.getString("channelTitle");" pubdate="snippet.getString("publishedAt");" thumbs="snippet.getJSONObject("thumbnails");" thumb="thumbs.getJSONObject("default");" final ico="thumb.getString("url");" new thread(new runnable() { public void run() bmp="ImageManager.downloadImage(ico);" } }).start(); countrylist.add(createemployee(title,channeltitle,pubdate, bmp)); simpleadapter.notifydatasetchanged();< code></jsonmainnode.length();i++){>
<br / > Update Listview's going on, but do not load this picture. Update ListView occurs on the button
July 2nd 19 at 17:06
1 answer
July 2nd 19 at 17:08
picasso and do not reinvent the wheel
Thank you. I tried Picasso. Can specify how to use Pacasso in this context to obtain the bmp and adding it to the HashMap - melba.Kiehn commented on July 2nd 19 at 17:11
: just feed it the url of the picture, if you need a bitmap, picasso allows you to do it with Target (if you just need to show a picture then you dont need this)
PS no offense, but You have mess in the code, describe the normal model, use retrofit or analog, the adapter does not need to know anything about json or something similar - xavier.Breitenberg21 commented on July 2nd 19 at 17:14

Find more questions by tags Android