Asynchronous image downloader in listview [Android]

I am having trouble embedding an asynchronous image loader in the following code. I read some posts on the Internet about this, and I think I understand the logic behind it, but it seems I am not following it.

Below is the code that I use to easily upload images to my list.

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;
   }
}
+5
source share
3 answers

You can use my sample code as a link Lazy loading images in a ListView

+8
source

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

(:

ImageView URL- , SmartImage .

+1

, , ArrayList "ImageView listDescription"

ArrayList<ImageView> allImageViews = new ArrayList<ImageView>();    
    ...

    public View getView(int position, View convertView, ViewGroup parent){
       ...
       ImageView listDescription=(ImageView)row.findViewById(R.id.listdescription);
       allImageViews.add(listDescription);
       ...
    }

    private class ImageDownLoader extends AsyncTask<ArrayList, Void, Void>{
       doInBackground(){
         for(ImageView imageView: allImageViews){
         BitmapFactory.Options bmOptions;
         bmOptions = new BitmapFactory.Options();
         bmOptions.inSampleSize = 1;
         bm = LoadImage(imageNameOrWhatever, bmOptions);
         imageView.setImageBitmap(bm);
       } 
    }

AsyncTask, ImageView, ImageView ArrayList. , .

0
source

All Articles