【问题标题】:How To Show Progress In Percentage For All Files如何以百分比显示所有文件的进度
【发布时间】:2019-11-21 12:16:58
【问题描述】:

如何实现一个进度条,以从 0% 到 100%(所有文件)的百分比显示所有文件的下载进度。这就是我的异步的样子:

    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();
            }
        }
}

【问题讨论】:

标签: android android-asynctask


【解决方案1】:

应该是

   @Override
    protected void onProgressUpdate(Void... values) {
      this.progressDialog.setProgress(Integer.parseInt(values[0]));
    }

【讨论】:

  • 我的活动中没有调用此方法 Log.d("LOG", "update: " +values[0]);
猜你喜欢
  • 1970-01-01
  • 2017-12-21
  • 1970-01-01
  • 2017-04-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-24
  • 2014-04-25
相关资源
最近更新 更多