0

How can I implement a progress bar that will show the progress download of all files in percentage from 0% to 100% (all files). This is how my async looks like:

    public class DownloadFileFromFTP extends AsyncTask<String, Void, String> {
        private Context context;
        private ProgressDialog progressDialog;

        public DownloadFileFromFTP(Context context) {
            this.context = context;
            this.progressDialog = new ProgressDialog(MyActivity.this);
            this.progressDialog.setCancelable(false);
         this.progressDialog.setMessage("Please wait...");
            this.progressDialog.show();
        }

        protected void onPreExecute() {
        }

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

    //code to list ftp files

            return null;
        }

        @Override
        protected void onProgressUpdate(Void... values) {
            super.onProgressUpdate(values);
        }

        @Override
        protected void onPostExecute(String result) {
            if (this.progressDialog != null) {
                this.progressDialog.dismiss();
            }
        }
}
CodeWithVikas
  • 1,105
  • 9
  • 33
TwoStarII
  • 351
  • 3
  • 17

1 Answers1

1

Its should be

   @Override
    protected void onProgressUpdate(Void... values) {
      this.progressDialog.setProgress(Integer.parseInt(values[0]));
    }
sasikumar
  • 12,540
  • 3
  • 28
  • 48
  • This method is not being called in my activity Log.d("LOG", "update: " +values[0]); <- No log cat also I had to change it to: progressDialog.setProgress(Integer.parseInt(String.valueOf(values[0]))); – TwoStarII Nov 22 '19 at 09:05