android: how do I check if dialogfragment is showing
if (dialogFragment != null
&& dialogFragment.getDialog() != null
&& dialogFragment.getDialog().isShowing()
&& !dialogFragment.isRemoving()) {
//dialog is showing so do something
} else {
//dialog is not showing
}
UPDATE: team can you also try the below call, i think it will work logically:
dialogFragment.isResumed
that should mean its in the foreground displaying if im not mistaken.
I added this to be inside my custom dialog fragment, so I don't have to worry about any logic on the outside. Override the show()
and onDismiss()
methods, with a boolean shown
field:
private static boolean shown = false;
@Override
public void show(FragmentManager manager, String tag) {
if (shown) return;
super.show(manager, tag);
shown = true;
}
@Override
public void onDismiss(DialogInterface dialog) {
shown = false;
super.onDismiss(dialog);
}
If you want to check whether it is shown or not, you can create a getter for the shown
boolean.