Search code examples
androidandroid-fragmentsandroid-dialogfragmentandroid-listfragmentchild-fragment

How do I programmatically add this fragment to my fragment?


I am trying to display a nested ListFragment inside my DialogFragment.

Apparently I cannot just declare a <fragment> in the XML for my DialogFragment layout because fragments-in-fragments need the childFragmentManager. So I am trying to do this in my DialogFragment:

Fragment listfragment = new ClassThatExtendsListFragment();
FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
transaction.add(????????, listfragment).commit();

I have absolutely no idea what resource ID I need to put in the ???????? section, or how I'd even go about assigning it.


Solution

  • simply add FrameLayout in you layout. suppose you gave it's id as "container",

    Fragment exampleFragment = new ExampleFragment();
        getSupportFragmentManager().beginTransaction()
                .add(R.id.container, exampleFragment).commit();