Max Usanin
Max Usanin

Reputation: 2499

How add a DialogFragment in a normal Fragment?

This source showed DialogFragment created new Fragment and blocked all screen (FragmentActivity). I need to add a Dialog in the Fragment so that when I can scroll the screen and the DialogFragment will not interfere. Current code:

FragmentManager fm = fa.getSupportFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();
            // create dlg fragment
            DialogFragment fragment = new DialogFragment();
            // show the dialog.
            fragment.show(fm, "android:switcher:888889:1"); // "android:switcher:888889:1" - existing fragment!

enter image description here

Upvotes: 2

Views: 2002

Answers (1)

user
user

Reputation: 87064

i need to add Dialog in the "fragment" Then I can scroll the screen and FragmentDialog will not interfere

A normal DialogFragment(or normal Dialog) will not work for what you want. Insted you could make use of nested Fragments. More precisely you'll need to modify your current Fragment's view from the ViewPager to wrap their current layout with a RelativeLayout or a FrameLayout along with adding another container(a FrameLayout) on top of the content.

That extra FrameLayout on top will be used as a Dialog holder(so the Dialog will appear as floating on top of the normal content) and to this container you'll add a Fragment to represent the Dialog(a normal Fragment, not a DialogFragment). You'll then be able to swipe the ViewPager even with your fake Dialog showing.

Also, keep in mind that swiping the ViewPager although a Dialog is showing on the screen, might be counter intuitive for the user.

Upvotes: 1

Related Questions