Comment rejeter par programme un DialogFragment? Je crée actuellement des dialogues par:
void showDialogWithId(int id){
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
Fragment prev = getSupportFragmentManager().findFragmentByTag("dialog");
if (prev != null) {
ft.remove(prev);
}
ft.addToBackStack(null);
if (id == SEARCHING_DIALOG){
// Create and show the dialog.
DialogFragment newFragment = MyDialogFragment.newInstance(SEARCHING_DIALOG,"TEST");
newFragment.show(ft, "dialog");
}
if (id == CONNECTING_DIALOG){
// Create and show the dialog.
DialogFragment newFragment = MyDialogFragment.newInstance(CONNECTING_DIALOG,"TEST");
newFragment.show(ft, "dialog");
}
if (id == CONNECTIVITY_DIALOG){
// Create and show the dialog.
DialogFragment newFragment = MyDialogFragment.newInstance(CONNECTIVITY_DIALOG);
newFragment.show(ft, "dialog");
}
}
Et je compte les licencier par:
public void dismissDialog(){
getFragmentManager().popBackStack();
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
Fragment prev = getSupportFragmentManager().findFragmentByTag("dialog");
if (prev != null) {
ft.remove(prev);
}
ft.addToBackStack(null);
}
Cependant, les dialogues ne sont pas fermés ...