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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:55:54+00:00 2026-05-24T19:55:54+00:00

I am having a strange issue, I have a new asynctask launced whenever i

  • 0

I am having a strange issue, I have a new asynctask launced whenever i find an MP3 file on webbrowser, and lauch a progress bar in the listview for each AsyncTask. So number of downloads can be more than 1 and simultaneous. But now whenever Asynctask is launced ProgressBar moves same for all and not different for different AsyncTask, Plz guide me…….

LISTVIEW WITH PROGRESS BAR

    public class CopyOfDownloadsListActivity extends ListActivity {
    /** Called when the activity is first created. */

//  static ArrayList<String> pthreads = new ArrayList<String>();
ImageView bt;
ProgressBar pb;
ListView allList;
TextView tv;
String fileName;
String mp3URL;
    URL url2;
    int filecount  = 0;

private class DownloadFile extends AsyncTask<String, Integer, Void>{
    MyCustomAdapter adapter;

    int count = 0;
    ProgressDialog dialog;
    ProgressBar progressBar;
    int myProgress;

   @Override        
    protected Void doInBackground(String... u) {        
        try {                   
            URL ul = new URL(u[0]);
            Log.i("UI",ul.toString());
       //   int len = CopyOfMusicDownloader.mp3urls.size();
       //   URL url2 = new URL(CopyOfMusicDownloader.mp3urls.get(len-1));
            HttpURLConnection c = (HttpURLConnection) ul.openConnection();
            c.setRequestMethod("GET");
            c.setDoOutput(true);
            c.connect();

            int lengthOfFile = c.getContentLength();

            String PATH = Environment.getExternalStorageDirectory()
                    + "/download/";
            Log.v("", "PATH: " + PATH);
            File file = new File(PATH);
            file.mkdirs();

            fileName = "Track";
            filecount++;

            fileName =  fileName + Integer.toString(filecount) + ".mp3";


            File outputFile = new File(file, fileName);
            FileOutputStream fos = new FileOutputStream(outputFile);
            InputStream is = c.getInputStream();

            byte[] buffer = new byte[1024];
            int len1 = 0;      
            while ((len1 = is.read(buffer)) != -1) {
                myProgress = (int)((len1/lengthOfFile)*100);
                myProgress = myProgress + myProgress;
                Log.i("lengthOfFile", Integer.toString(lengthOfFile));
                Log.i("My Progress", Integer.toString(myProgress));
                publishProgress(myProgress);
                fos.write(buffer, 0, len1);
            }
            fos.close();
            is.close();

            }catch (IOException e) {
                   e.printStackTrace();
            }
        return null;
    }

    protected void onPostExecute() {
    }

    @Override
    protected void onPreExecute() {         
          adapter = new MyCustomAdapter(CopyOfDownloadsListActivity.this, R.layout.row, CopyOfMusicDownloader.mp3urls);
          setListAdapter(adapter);
    }



    @Override
    protected void onProgressUpdate(Integer... values) {
         Log.i("Value", values[0].toString());
         count++;
         adapter.notifyDataSetChanged();
    }


    public class MyCustomAdapter extends ArrayAdapter<String> {     
        public MyCustomAdapter(Context context, int textViewResourceId, ArrayList<String> pthreads) {
        super(context, textViewResourceId, pthreads);
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
                LayoutInflater inflater = getLayoutInflater();
                View row = inflater.inflate(R.layout.row, parent, false);
                bt =(ImageView)row.findViewById(R.id.cancel_btn);
                tv =(TextView)row.findViewById(R.id.filetext);
                pb = (ProgressBar)row.findViewById(R.id.progressbar_Horizontal);
                pb.setProgress(count);  
                return row;
            }
        }       
 }  

This is the AsyncTask start, and its onCreate
new DownloadFile().execute(url2.toString());

  • 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-05-24T19:55:55+00:00Added an answer on May 24, 2026 at 7:55 pm

    Your issue is this static ProgressBar pb;

    You can’t have a single static reference and expect to control multiple progress bars. Fully encapsulate the ProgressBar inside the AsyncTask, make it a instance variable.

    EDIT

    In onProgressUpdate you need to change the progress of the ProgressBar. You don’t need an adapter for every row, its wasteful.

    @Override
        protected void onProgressUpdate(Integer... values) {
             Log.i("Value", values[0].toString());
             count++;
             progressBar.setProgress(count);
        }
    

    You also never assign a value progressBar, you keep assessing pb, get rid of that variable! In you PreExecute you keep reassigning the List’s adapter.

    You need A LOT of modifications. Create a single adapter that manages the listview. Each row can have an AsyncTask that maintains its own progress bar, image view and text view.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Strange issue I am having with my MVC3 project. I have followed a simple
I am having a bit of a strange issue. I have a ListView which
I have a strange issue where i have a a HttpHandler having its ProcessRequest()
Having a strange issue with the TabContainer in the AJAX Toolkit. We have several
I'm having a strange issue here, i have this bit of code: <?php if
I am having a strange issue in my flex app. I have a Video
I'm having a very strange issue, it looks like my application can't create file
I'm having this strange issue where I have an NSArrayController bound to a managedObjectContext
I'm having a strange issue with webdriver. I have a local environment and a
I am having a really strange issue with my edit page: If I have

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.