質問

I have a FragmentDialog sppearing in front of a GoogleMap that I want to temporarily hide so that the user can select something on the background, and then bring it back in front again. Regular hide()/show() won't work since it's not "embedded" fragment, but a FragmentDialog cannot be hidden. I tried to use dismiss() and then show() using the same instance, since that should recreate the dialog, but it doesn't seem to work for some reason. Here's my code:

 if (onHoldDialog != null) {
        onHoldDialog.setPointText(mapMarker.getTitle());

        FragmentTransaction ft = getFragmentManager().beginTransaction();
        Fragment prev = getFragmentManager().findFragmentByTag("dialog");
        if (prev != null) {
            ft.remove(prev);
        }
        ft.addToBackStack(null);

        onHoldDialog.show(ft, "dialog");
}

Is my method wrong? Are FragmentDialog instances only "one-use"? Can I copy it to another instance?

役に立ちましたか?

解決

The problem I had was I overrode onDismiss in my DialogFragment subclass, but I didn't call super.onDismiss. Once I called the super's method, the problem was fixed.

In general, remember to call the super method of an overridden method in fragments and activities.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top