Asynchronous image loader on listview [Android]

27,191

Solution 1

You may use my sample code as reference Lazy load of images in ListView

Solution 2

Have you looked SmartImageView? http://loopj.com/android-smart-image-view/

It's very simple library to load images asynchronously (:

some Features of this library

Drop-in replacement for ImageView Load images from a URL Load images from the phone’s contact address book Asynchronous loading of images, loading happens outside the UI thread Images are cached to memory and to disk for super fast loading SmartImage class is easily extendable to load from other sources

Share:
27,191
thpoul
Author by

thpoul

Updated on August 06, 2020

Comments

  • thpoul
    thpoul almost 4 years

    I'm having problems implementing an asynchronous image loader to the following code. I read some posts around the web about it and I think I understand the logic behind it, but I seem to fail in implementing it.

    The code bellow is what I use to simply load the images in my listview.

    public class MyCustomAdapter extends ArrayAdapter<RSSItem> {
       Bitmap bm;
    
       public MyCustomAdapter(Context context, int textViewResourceId, List<RSSItem> list) {
          super(context, textViewResourceId, list); 
       }
    
       @Override
       public View getView(int position, View convertView, ViewGroup parent) {
          // TODO Auto-generated method stub
          BitmapFactory.Options bmOptions;
          bmOptions = new BitmapFactory.Options();
          bmOptions.inSampleSize = 1;
          bm = LoadImage(myRssFeed.getList().get(position).getDescription(), bmOptions);
    
          View row = convertView;
    
          if(row == null) {
             LayoutInflater inflater = getLayoutInflater();
             row = inflater.inflate(R.layout.rsslist, parent, false); 
          }
    
          TextView listTitle = (TextView)row.findViewById(R.id.listtitle);
          listTitle.setText(myRssFeed.getList().get(position).getTitle());
          ImageView listDescription = (ImageView)row.findViewById(R.id.listdescription);
          listDescription.setImageBitmap(bm);
          TextView listPubdate = (TextView)row.findViewById(R.id.listpubdate);
          listPubdate.setText(myRssFeed.getList().get(position).getPubdate());
    
          return row;
       }
    }