我在DialogFragment中创建了以下类,它是ProgressDialog。问题是我想从其他片段更新对话框的进度。我怎么能这样做?谢谢
public class MaterialProgressDialogFragment extends DialogFragment {
private int total;
private MaterialDialog myDialog;
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return myDialog;
}
public void incrementProgress(int by) {
myDialog.incrementProgress(by);
}
public void setTotal(int total) {
this.total = total;
}
public void setUp(Context context) {
myDialog = new MaterialDialog.Builder(context)
.title("Progreso")
.content("Procesando las fotos seleccionadas...")
.progress(false, total, true)
.build();
}
}
然后在我的片段中:
MaterialProgressDialogFragment dialogFragment = new MaterialProgressDialogFragment();
dialogFragment.setTotal(100);
dialogFragment.setUp(getActivity());
dialogFragment.show(getActivity().getSupportFragmentManager(), "");
dialogFragment.incrementProgress(50);
一切都按预期工作,直到我调用incrementProgress