title: Update progress bar in listview for multi files download
body: <p>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.</p>
  
  <p>The feature will be:</p>
  
  <ol>
  <li>Each progress bar will be update with downloading process.</li>
  <li>When a file complete downloaded  it will be save into sd card.</li>
  <li>It will be added it service(Running on the background.</li>
  <li>When one file downloaded it should show "Complete "(should not be remove form listview)</li>
  </ol>
  
  <p>I also used a database for downloading the file.The list also depends on the  database vector. How  can I implement it. I also tried but did not get solution.</p>
  
  <p>Below are the two screenshots to describe it in detail:</p>
  
  <p><img src="https://i.stack.imgur.com/k4ICg.png" alt="enter image description here"></p>
  
  <p>I also tried this code:</p>
  
  <pre><code>temp = databaseHandler.getAllNotifyNumber();
  list_download = (ListView) findViewById(R.id.list_download);
  myCustomAdapter = new MyCustomAdapter(mContext);
  list_download.setAdapter(myCustomAdapter);
  myCustomAdapter.notifyDataSetChanged();
  
  for (int index = 0; index &lt; temp.size(); index++) {
      String url = "http://upload.wikimedia.org/wikipedia/commons/0/05/Sna_large.png";
      grabURL(url);
  }
  </code></pre>
  
  <p>This is AsyncTask mathod:</p>
  
  <pre><code>  public void grabURL(String url) {
      new GrabURL().execute(url);
  }
  
  private class GrabURL extends AsyncTask&lt;String, Integer, String&gt; {
  
      protected String doInBackground(String... urls) {
  
          String filename = "MySampleFile.png";
          File myFile = new File(directory, filename);
  
          try {
              URL url = new URL(urls[0]);
              URLConnection connection = url.openConnection();
              connection.connect();
              int fileSize = connection.getContentLength();
  
              InputStream is = new BufferedInputStream(url.openStream());
              OutputStream os = new FileOutputStream(myFile);
  
              byte data[] = new byte[1024];
              long total = 0;
              int count;
              while ((count = is.read(data)) != -1) {
                  total += count;
                  publishProgress((int) (total * 100 / fileSize));
                  os.write(data, 0, count);
              }
  
              os.flush();
              os.close();
              is.close();
  
          } catch (Exception e) {
              e.printStackTrace();
          }
  
          return filename;
  
      }
  
      @Override
      protected void onProgressUpdate(Integer... progress) {
          // home_countprogress.setVisibility(View.VISIBLE);
          // home_countprogress.setText(String.valueOf(progress[0]) + "%");
          // progressbar_horizontal.setProgress(progress[0]);
          myCustomAdapter.notifyDataSetChanged();
      }
  
      @Override
      protected void onCancelled() {
          Toast toast = Toast.makeText(getBaseContext(),
                  "Error connecting to Server", Toast.LENGTH_LONG);
          toast.setGravity(Gravity.TOP, 25, 400);
          toast.show();
  
      }
  
      @Override
      protected void onPostExecute(String filename) {
          // progressbar_horizontal.setProgress(100);
          // home_countprogress.setVisibility(View.VISIBLE);
      }
  
      protected void onPreExecute() {
          // progressbar_horizontal.setVisibility(View.VISIBLE);
          // progressbar_horizontal.setProgress(0);
          // home_countprogress.setVisibility(View.VISIBLE);
  
          myCustomAdapter = new MyCustomAdapter(mContext);
  
      }
  }
  </code></pre>