2
我需要更新AsyncTask
中的進度對話框片段。我知道如何使用舊的ProgressDialog
來做到這一點,但現在這種顯示對話框的方式已被廢棄,我正在嘗試使用Fragments做同樣的事情。如何更新ProgressDialog片段
這是片段代碼:
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中檢索底層對話框?這樣做的正確方法是什麼? (如果對話框被重新創建,我不想泄漏引用)。
在此先感謝。