进度条填充100%后隐藏自定义对话框

时间:2016-07-17 15:48:45

标签: android firebase progress-bar alertdialog firebase-storage

我尝试在将文件上传到firebase服务器时显示带有进度条的自定义对话框。一切正常。但是当我在进度条填充100%后尝试隐藏对话框时(在成功监听器上添加了dialog.dimiss())。它甚至停止更新进度条

Dialog dialog:
          uploadTask.addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
                @Override
                public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
                    double progress = (100.0 * taskSnapshot.getBytesTransferred()) / taskSnapshot.getTotalByteCount();
                      dialog = new Dialog(mainpanel.this);
                    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
                    lp.copyFrom(psdialog.getWindow().getAttributes());
                    lp.width = WindowManager.LayoutParams.MATCH_PARENT;
                    lp.height = WindowManager.LayoutParams.WRAP_CONTENT;

                   dialog.setContentView(R.layout.progressbarlayout);
                    dialog.setTitle("Custom Dialog");

                    View dialogView = LayoutInflater.from(getApplicationContext()).inflate(R.layout.progressbarlayout, null, false);
                    dialog.setContentView(dialogView);
                   status = (ProgressBar) dialogView.findViewById(R.id.progressbar);

status.setProgress(currentprogress);

                   dialog.show();
                   dialog.getWindow().setAttributes(lp);
                }
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
            @Override
            public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {

                Uri downloadUrl = taskSnapshot.getDownloadUrl();

             Context context = getApplicationContext();
                CharSequence text = "upload succesful";
                int duration = Toast.LENGTH_LONG;
                Toast toast = Toast.makeText(context, text, duration);
                toast.show();
              dialog.dismiss();

0 个答案:

没有答案