J'utilise un DialogFragment pour renvoyer un DatePickerDialog dans onCreateDialog(). J'ai mis le dateSetListener à DialogFragment ("ceci" dans l'exemple ci-dessous) et tout fonctionne sauf que onDateSet() est appelé quand une rotation d'écran se produit, ce qui n'est pas souhaitable. Comment puis-je obtenir onDateSet pour ne pas être appelé lorsque l'écran est pivoté?DatePickerDialog onDateSet appelé lors de la rotation
Mon 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();
}
}
Et voilà comment je l'appelle
if(getActivity()!=null){
FragmentManager fm = getActivity().getSupportFragmentManager();
DialogFragment newFragment = DateDialogFragment.newInstance();
newFragment.show(fm, "dialog");
}
Jetez un oeil à [setRetainInstance()] (http://stackoverflow.com/questions/11182180/understanding-fragments-setretaininstanceboolean) – Dmide
suis-je raison ? vous ne voulez pas rappeler sur ** dateset ** méthode lorsque l'écran a tourné –
Depuis la publication d'une prime sur cette question, j'ai découvert qu'il s'agit d'un doublon de http://stackoverflow.com/questions/11444238/jelly-bean- datepickerdialog-est-il-un-way-to-cancel mais je ne peux pas voter pour le fermer à cause de ma prime. –