我使用以下代码按照新的“片段方式”创建了一个进度对话框:
public class DialogUpdateTrackRecords extends DialogFragment {
public static DialogUpdateTrackRecords newInstance() {
DialogUpdateTrackRecords frag = new DialogUpdateTrackRecords();
return frag;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public ProgressDialog onCreateDialog(Bundle savedInstanceState) {
this.setCancelable(false);
ProgressDialog dialog= new ProgressDialog(getActivity());
dialog.setTitle("Caricamento tragitti");
dialog.setIndeterminate(true);
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
dialog.setMessage("Sending something");
return dialog;
}
}
我从这样的活动中展示它:
FragmentManager fm= getSupportFragmentManager();
uploadDialogFrament= (DialogFragment) getSupportFragmentManager().findFragmentByTag("sendDialog");
if(uploadDialogFrament!=null)
uploadDialogFrament.dismiss();
FragmentTransaction ft= fm.beginTransaction();
uploadDialogFrament= DialogUpdateTrackRecords.newInstance();
uploadDialogFrament.show(ft,"sendDialog");
fm.executePendingTransactions();
((ProgressDialog)uploadDialogFrament.getDialog()).setMax(trackRecordSize);
if( trackRecordSize > 1 )
((ProgressDialog)uploadDialogFrament.getDialog()).setIndeterminate(false);
如您所见,我得到了对对话框的引用并设置了它(取决于我的需要)。一切都像魅力一样,但是..如果我旋转设备,对话框会回到原始状态,而不是保留(在示例中:栏设置回不确定状态)我的新设置。我检查了我是否错误地创建和显示了一个新对话框,但事实并非如此。那么..我怎样才能在活动的娱乐中保持我的变化?