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 8477247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:24:36+00:00 2026-06-10T18:24:36+00:00

Description: I have a grid view with 4 items in landscape mode and 3

  • 0

Description:
I have a grid view with 4 items in landscape mode and 3 items on portrait mode. The grid element is a magazine thumbnail. On click of a thumbnail downloading of the magazine starts and a horizontal progress bar appears showing progress of download. But when i click to two thumbnails one after another , the progress bar of later clicked thumbnail only updates and at last corrupted magazine gets downloaded.
I have used asynchronous task for magazine download.

Code:

public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {


    progress = (ProgressBar) arg1.findViewById(R.id.progress);
    thumbnail = (ImageView) arg1.findViewById(R.id.thumbnail);



    thumbnail.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // Download Magazine
             downloadMagazine.execute(bank.get(index).getPdfLink());

            }
    });

}


class DownloadMagazineTask extends AsyncTask<String, Integer, Long> {
    File sdDir = Environment.getExternalStorageDirectory();

    @Override
    protected void onPreExecute() {

       progress.setVisibility(View.VISIBLE);

    }

    @Override
    protected Long doInBackground(String... arg0) {

        String[] urls = arg0;

        try {
            URL url = new URL(urls[0]);
            URLConnection con = url.openConnection();
            int fileLength = con.getContentLength();

            InputStream input = new BufferedInputStream(url.openStream());

            File file = null;

            File dir = new File(sdDir + "/BeSpoken/pdfs");
            boolean flag = dir.mkdirs();
            if (flag)

                System.out.println("Directory created");
            else {
                System.out.println("Directory not created");
                file = new File(dir+ "/"+ bank.get(index).getPdfLink().substring(bank.get(index).getPdfLink().lastIndexOf("/")));

            }
            OutputStream output = new FileOutputStream(file);

            byte data[] = new byte[1024];
            long total = 0;

            int count;
            while ((count = input.read(data)) != -1) {
                total += count;
                // publishing the progress....
                publishProgress((int) (total * 100 / fileLength));
                output.write(data, 0, count);
            }


            String m = bank.get(index).getTitle();
            manager.updateDownloadedMagazines(
                    Integer.parseInt(m.substring(m.lastIndexOf(" ") + 1)),
                    file.toString());
            output.flush();
            output.close();
            input.close();

        } catch (Exception e) {
            e.printStackTrace();
        }
        startActivity(getIntent());
        finish();

        return null;
    }

    @Override
    protected void onProgressUpdate(Integer... values) {

        super.onProgressUpdate(values);
        progress.setProgress(values[0]);

    }

    @Override
    protected void onPostExecute(Long result) {

        super.onPostExecute(result);

        progress.setVisibility(View.INVISIBLE);



    }

}

Question:
How can i implement multiple download functionality so that progress bar shows progress of each download individually??

  • 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-10T18:24:38+00:00Added an answer on June 10, 2026 at 6:24 pm

    I have defined the image view and the progress bar as final and sending these references to the AsyncTask where the magazine downloading activity is going, on click of image view.
    AsyncTask spawns multiple threads and that’s how progress of each download can be updated.Code:

       @Override
        public View getView(final int position, View convertView, ViewGroup arg2) {
    
            View grid;
    
            if (convertView == null) {
                grid = new View(context);
                grid = layoutInflater.inflate(item, null);
    
            } else {
                grid = (View) convertView;
            }
    
            final TextView title = (TextView) grid.findViewById(R.id.mgntitle);
            title.setText(bank.get(position).getTitle());
            final ImageView imageView = (ImageView) grid
                    .findViewById(R.id.thumbnail);
            imageView.setImageResource(R.drawable.icon);
            final ProgressBar progress = (ProgressBar) grid
                    .findViewById(R.id.progress);
            final ImageView downloadmark = (ImageView) grid
                    .findViewById(R.id.downloadmark);
            String pdfLink = bank.get(position).getPdfLink();
            String filename = pdfLink.substring(pdfLink.lastIndexOf("/") + 1);
            final File targetDir = new File(fileLocation + filename);
            System.out.println("target file name " + targetDir);
    
            if (new File(fileLocation + filename).exists()) {
                if (!getPrefName(filename).equalsIgnoreCase("NA")) {
                    downloadmark.setVisibility(View.VISIBLE);
                }
            }
    
    
    
            imageView.setOnClickListener(new View.OnClickListener() {
    
                @Override
                public void onClick(View v) {
    
                    if (!targetDir.exists()) {
                            map.put(bank.get(position).getTitle(), progress);
                            new DoBackgroundTask(GridDisplayActivity.this, bank
                                    .get(position).getPdfLink(), progress,
                                    downloadmark, imageView, position)
                                    .execute();
    
    
                    }
    
    
                }
    
            });
    
            imageView.setImageBitmap(BitmapFactory.decodeByteArray(
                    bank.get(position).getCoverPages(), 0, bank.get(position)
                            .getCoverPages().length));
    
    
            return grid;
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one grid view with 4 columns(UserId,Description,Password,Change Password[Button]). When i click on change
So I have a grid view with checkboxes in it. This is the code
I have an issue with having a asp.net Grid View loaded into a div
I have the following partial view code @model IEnumerable<PDoc.Web.Models.UserDocModel> @using MvcContrib.UI.Grid; @using MvcContrib.UI.Pager; @using
I have one grid view which i want to add in footer of listview
I have about 50 images with in a grid view within my Android app.
I have data grid view with columns product name and product image and I
I have two View Controllers, one with a grid of buttons, and the second
I have a strongly typed Category View, showing all Category (in a grid) ...
I have 5 check box on my page and a Grid view with Template

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.