我需要从AsyncTask
. 我知道如何使用 old 来做到这一点ProgressDialog
,但现在这种显示对话框的方式已被弃用,我正在尝试对 Fragments 做同样的事情。
这是片段代码:
public static class CustomProgressDialogFragment extends SherlockDialogFragment {
static CustomProgressDialogFragment newInstance(Object... params){
CustomProgressDialogFragment df = new CustomProgressDialogFragment();
Bundle bundle = new Bundle();
// Populate bundle with params (not shown)
df.setArguments(bundle);
return df;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setCancelable(false);
int style = DialogFragment.STYLE_NORMAL, theme = 0;
setStyle(style,theme);
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Bundle bundle = this.getArguments();
ProgressDialog dialog = new ProgressDialog(getActivity());
// Get params from bundle and customize dialog accordingly (not shown)
dialog.setCancelable(false);
dialog.setIndeterminate(false);
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
return dialog;
}
}
这就是我展示它的方式:
FragmentTransaction ft = this.getSupportFragmentManager().beginTransaction();
CustomProgressDialogFragment dialogFragment = CustomProgressDialogFragment.newInstance(<My params here>);
ft.disallowAddToBackStack();
ft.add(dialogFragment, stringSet.tag);
ft.commitAllowingStateLoss();
现在我需要incrementProgressBy
从 AsyncTask 调用对话框。有没有办法从 FragmentManager 检索底层对话框?这样做的正确方法是什么?(如果重新创建对话框,我不想泄露引用)。
提前致谢。