Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9136105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:54:34+00:00 2026-06-17T08:54:34+00:00

In java I want to download multiple images for my imageview at once. I

  • 0

In java I want to download multiple images for my imageview at once. I found this code which does exact that but its only downloading the first image. I think it has something to do with the first line in the doInBackground. How can I tweak this code so it loops imageViews and downloads every image for imageViews.

package com.denederlandsewateren.daos;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.util.Log;
import android.widget.ImageView;

public class DownloadImageTaskDAO extends AsyncTask<ImageView, Void, Bitmap> {

    ImageView imageView = null;

    @Override
    protected Bitmap doInBackground(ImageView... imageViews) {
        this.imageView = imageViews[0];
        return download_Image((String)imageView.getTag());
    }

    @Override
    protected void onPostExecute(Bitmap result) {
        imageView.setImageBitmap(result);
    }

    private Bitmap download_Image(String url) {
        //---------------------------------------------------
        Bitmap bm = null;
        try {
            URL aURL = new URL(url);
            URLConnection conn = aURL.openConnection();
            conn.connect();
            InputStream is = conn.getInputStream();
            BufferedInputStream bis = new BufferedInputStream(is);
            bm = BitmapFactory.decodeStream(bis);
            bis.close();
            is.close();
        } catch (IOException e) {
            Log.e("Hub","Error getting the image from server : " + e.getMessage().toString());
        } 
        return bm;
        //---------------------------------------------------
    }

}

called from here:

public void setImages(String url1, String url2) {
        image1.setTag(url1);
        image2.setTag(url2);
        DownloadImageTaskDAO imageDAO = new DownloadImageTaskDAO();
        imageDAO.execute(image1, image2);
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:54:35+00:00Added an answer on June 17, 2026 at 8:54 am
    @Override
    protected Bitmap doInBackground(ImageView... imageViews) {
        this.imageView = imageViews[0];
        return download_Image((String)imageView.getTag());
    }
    

    You are processing only the first argument sent to the AsyncTask. With the parameter ImageView... you can send one, two, N elements or arrays. Loop through the arguments and process each one.

    You can use the return from doInBackground, in onPostExecute and personally I try to utilize that as much as I can for the sake of encapsulation.

    Overall I suggest you read the AsyncTask reference on Android Developers to get a better understanding of AsyncTasks.

    I did rewrite your code and below should theoretically work (it’s not tested).

    public class DownloadImageTaskDAO extends AsyncTask<ImageView, Void, ArrayList<DownloadImageTaskDAO.Container>> {
    
        @Override
        protected ArrayList<Container> doInBackground(ImageView... imageViews) {
             ArrayList<Container> results = new ArrayList<Container>(imageViews.length);
    
             for (ImageView imageView : imageViews) {
                 Container tmp = new Container();
                 tmp.holder = imageView;
                 tmp.image = download_Image(imageView.getTag().toString());
                 results.add(tmp);
             }
    
             return results;
        }
    
        @Override
        protected void onPostExecute(ArrayList<Container> result) {
            for (Container container : result) {
                container.holder.setImageBitmap(container.image);
            }
        }
    
        private Bitmap download_Image(String url) {
            ....
        }
    
        class Container {
            ImageView holder;
            Bitmap image;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im a getting errors from some code developed in Java that want to use
I want to display an image in my Java application. I found a code
I'm doing a project on java download manager.i want to download a single file(which
I want to make a Java downloader program, which will download the data from
I found a java code and want to use it in my project. It
I want to create a PHP/Java application that would be able to download videos
I want to download a HTTP query with java, but the file I download
I would like to know if this is possible in java that i want
is there a dictionary i can download for java? i want to have a
I want Java to be installed on my Leopard MacBook, but I couldn't find

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.