android: Display image from URL in ListView

In one of my projects, I used the following code for displaying images in ListView:

public Bitmap getBitmap(String bitmapUrl) {
    	  try {
    	    URL url = new URL(bitmapUrl);
    	    return BitmapFactory.decodeStream(url.openConnection().getInputStream()); 
    	  }
    	  catch(Exception ex) {return null;}
    	}

and then

Bitmap bitmap = getBitmap(thumbnailUrl);
ImageView image = (ImageView) view.findViewById(R.id.avatar);
image.setImageBitmap(bitmap);

This solution is pretty simple, but the problem is in performance. Scrolling list takes long time to show.
Then I found solution provided by Fedor Vlasov in post Android – How do I do a lazy load of images in ListView.
Get code from github repository.

my code turned to

Bitmap bitmap = getBitmap(thumbnailUrl);
ImageView image = (ImageView) view.findViewById(R.id.avatar);

1 comment

Leave a Reply

%d bloggers like this: