开发者

DialogFragment not seen as visible when created with onCreateDialog

开发者 https://www.devze.com 2023-03-05 12:53 出处:网络
(Using the compatibility library) I have implemented a dialog with extends DialogFragment. I create the dialog using AlertDialog.Builder in onCreateDialog (onCreateView is not used).

(Using the compatibility library)

I have implemented a dialog with extends DialogFragment. I create the dialog using AlertDialog.Builder in onCreateDialog (onCreateView is not used).

In my fragment I invoke the dialog with:

dlg.show(getFragmentManager(), tag);

However, when I come to check visiblity, once the dialog is clearly visible, using

dlg.isVisible();

This returns false.

Now开发者_开发技巧 the following is the Fragment::isVisible code from the compatibility sources.

final public boolean isVisible() {
    return isAdded() && !isHidden() && mView != null
            && mView.getWindowToken() != null && mView.getVisibility() == View.VISIBLE;
}

The calls returns false because mView is null because the view isn't attached to a window.

Any ideas as to how I should be invoking the dialog, or creating it for that matter, so that it is attached to the fragment's root view? Or how else I should be checking for visibility?

Thanks in advance, Peter.


You can determine if a dialog fragment is showing by a function like:

boolean isShowing(DialogFragment dlg)
{
   return dlg.getDialog() != null;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消