我正在使用DialogFragment在onCreateDialog()中返回DatePickerDialog。我已經將dateSetListener設置爲DialogFragment(下例中的「this」),除了onDateSet()在發生屏幕旋轉時被調用,這是不可取的。如何讓onDateSet在屏幕旋轉時不被調用?DatePickerDialog onDateSet旋轉時調用
我DialogFragment
public static class DateDialogFragment extends DialogFragment implements
DatePickerDialog.OnDateSetListener{
public static DateDialogFragment newInstance() {
return new DateDialogFragment();
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new DatePickerDialog(getActivity(), this, 2012, 11, 19);
}
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
//This is called when screen rotated, which I dont want
Toast.makeText(getActivity(), "Year: "+year+" Month: "+monthOfYear+" Day: "+dayOfMonth, Toast.LENGTH_SHORT).show();
}
}
這是我怎麼稱呼它
if(getActivity()!=null){
FragmentManager fm = getActivity().getSupportFragmentManager();
DialogFragment newFragment = DateDialogFragment.newInstance();
newFragment.show(fm, "dialog");
}
看一看[setRetainInstance()](http://stackoverflow.com/questions/11182180/understanding-fragments-setretaininstanceboolean) – Dmide
我是正確的?你不想回顧** dateset **方法當屏幕旋轉 –
由於發佈在這個問題上的賞金,我發現它是一個http://stackoverflow.com/questions/11444238/jelly-bean- datepickerdialog-is-there-a-way-to-cancel但我不能投票結束,因爲我的賞金。 –