Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android: how do I check if dialogfragment is showing

I launch my dialog fragment using

FragmentTransaction ft =  getFragmentManager().beginTransaction(); MyDialogFragment dialog = new MyDialogFragment() dialog.show(ft, "dialog"); 

then to get a handle on it I do

Fragment prev = getFragmentManager().findFragmentByTag("dialog"); 

but once I get prev, how do I check if it is showing?

Back Story

My problem is that my looping code keeps launching the dialog again and again. But if the dialog is already showing, I don't want it to launch again. This back story is just for context. The answer I seek is not: "move it out of the loop."

like image 319
learner Avatar asked Jan 25 '14 15:01

learner


People also ask

How do I know if DialogFragment is showing?

that should mean its in the foreground displaying if im not mistaken. If you call DialogFragment's creation several times in one moment, dialogFragment = getSupportFragmentManager(). findFragmentByTag("dialog"); will return null, and all dialogs will be shown.

How can I tell if dialog is open Android?

Dialog has an isShowing() method that should return if the dialog is currently visible. So you can use that to see if a dialog is showing and hide it with dismissDialog().

How do I start a DialogFragment?

To create a DialogFragment , first create a class that extends DialogFragment , and override onCreateDialog() , as shown in the following example. Similar to how onCreateView() should create a root View in an ordinary fragment, onCreateDialog() should create a Dialog to display as part of the DialogFragment .

How do I close DialogFragment on Android?

tl;dr: The correct way to close a DialogFragment is to use dismiss() directly on the DialogFragment. Control of the dialog (deciding when to show, hide, dismiss it) should be done through the API here, not with direct calls on the dialog. Dismiss the fragment and its dialog.


1 Answers

 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.

like image 105
j2emanue Avatar answered Oct 04 '22 15:10

j2emanue