取消RxJava Observable

时间:2017-02-22 09:17:41

标签: java android alertdialog android-alertdialog rx-java2

我想要带有进度条的上传文件。我创建了AlertDialog

AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity());
View dialogView = View.inflate(getContext(), R.layout.dialog_upload_view, null);
progress = (NumberProgressBar) dialogView.findViewById(R.id.progress_bar);
progress.setProgress(0);
dialog.setView(dialogView);
dialog.setCancelable(false);
dialog.setNegativeButton(R.string.cancel, (DialogInterface dialogInterface, int i) -> Log.w("TEST", "Cancel"));
AlertDialog ad = dialog.show();

然后我上传文件

    Disposable disposable = Observable.fromArray(files.toArray())
            .flatMap(photo -> {
                ProgressRequestBody fileBody = new ProgressRequestBody(photo, this);
                MultipartBody.Part filePart = MultipartBody.Part.createFormData("userfile", photo.getName(), fileBody);
                return App.getEndpoints().addPhoto(filePart);
            })
            .subscribeOn(Schedulers.io())
            .doOnComplete(ad::dismiss)
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe();

如果我之后

dialog.setNegativeButton(R.string.cancel, (DialogInterface dialogInterface, int i) -> disposable.dispose());

按钮不显示。

如何设置对话框的否定按钮?

0 个答案:

没有答案
相关问题