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

  • Home
  • SEARCH
  • 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 6324337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:41:03+00:00 2026-05-24T16:41:03+00:00

How can we update a progress bar in ListView. When each progress bar is

  • 0

How can we update a progress bar in ListView. When each progress bar is associated download of a file and which is done via AsyncTask.

  • So where to update ProgressBar
    1. In update progress (I have tried this is not working)
    2. In the View Inflation process of ListView. (This is also not working)

Basically i whenever i get an file like .mp3 in browser, i call this asynctask, so there can be n instance of asynctask. but then how to update a particular progress bar with particular Aysnctask task.

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

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

            private class DownloadFile extends AsyncTask<String, Integer, Void>{
                int count = 0;
                ProgressDialog dialog;
                int myProgess = 0;
                ProgressBar progressBar;

                @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*100/lengthOfFile);
                            //myProgress = (int)(len1);

                            Log.i("My Progress", Integer.toString(myProgress));
                            publishProgress(myProgress);
                            //  publishProgress((int)(len1*100/lengthOfFile));
                            fos.write(buffer, 0, len1);
                        }
                        fos.close();
                        is.close();

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

                protected void onPostExecute() {

                }

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

                }



                @Override
                protected void onProgressUpdate(Integer... values) {
                     pb.setProgress(count);// HERE IS THE PROBLEM

                     count++;
                     Log.i("Values", Integer.toString(values[0]));
                }
             }  

            @Override
            public void onCreate(Bundle savedInstanceState) {
                requestWindowFeature(Window.FEATURE_NO_TITLE);
                super.onCreate(savedInstanceState);

                int len = CopyOfMusicDownloader.mp3urls.size();
                try {
                    url2 = new URL(CopyOfMusicDownloader.mp3urls.get(len-1));
                    new DownloadFile().execute(url2.toString());
                    Log.i("url",url2.toString());
                } catch (MalformedURLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

             }

            @Override
            public boolean onCreateOptionsMenu(Menu menu) {
                 MenuInflater myMenuInflater = getMenuInflater();
                 myMenuInflater.inflate(R.menu.menu, menu);
                return true;
            }

            @Override
            public boolean onOptionsItemSelected(MenuItem item) {
                 switch(item.getItemId()){
                 case(R.id.browsermenu):
                 Intent i = new Intent(CopyOfDownloadsListActivity.this, MusicDownloader.class);  
                 startActivity(i);
                 break;
                 case(R.id.downloaderrmenu):      
                 break; 
                 case(R.id.playermenu):
                 Intent j = new Intent(CopyOfDownloadsListActivity.this, Players.class);  
                 startActivity(j);
                break;
          }
             return true;
            }


            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);
                        return row;
                    }
                }


        }
  • 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-24T16:41:03+00:00Added an answer on May 24, 2026 at 4:41 pm

    Children of a list view are built by an adapter. This adapter has some underneath data that is ‘transformed’ to views in getView() method. This means you have to change that data in update progress method of async task and call adapter.notifyDataSetChanged(). And your getView method should just ‘transform’ data to the list view child.

    AsyncTask:

    protected void onProgressUpdate(final int... values) {
      data[i].progress = values[0];
      adapter.notifyDataSetChanged();
    }
    

    Adapter:

    public View getView(final int position, final View convertView, final ViewGroup parent) {
      ...
      progress.setProgress(getItem(position).progress);
      ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to Update the Progress bar in my application. I have created a
I want to update a progress bar from running 1 to 100 with this
I am trying to update a progress bar in my main form while a
I can't update my progressbar... this is my code Thread t=new Thread(new Runnable(){ public
I have built a long running script to which I have added a progress
If I have a managed Wix Custom Action, is there anyway I can update
I want to update a progress bar in winforms using delegate from task. scheduler
I have an algorithm which is executted in task from tpl. From each iteration
Can I update a progress of a loop using the yield keyword? foreach(something obj
I want to ajax upload a file to the server and update the progress

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.