0

I Tried putting a Fragment into a FrameLayout inside another Fragment via FragmentManager and FragmentTransaction (from android.support.v4.app). The container fragment has a button and a TextView on top and a FrameLayout at the bottom (I create the layout programmatically and i don't want to hurt your eyes with all of that). The CreateView() works just fine and i cann access the FrameLayout at the bottom of the container and add or remove View dynamically as I please via

@Override
public void onClick(View button) {      
    FrameLayout frame = (FrameLayout)findViewById(DETAIL_CONTENT_FRAME);
    ImageView im = new ImageView(this);
    im.setImageResource(R.drawable.test);
    frame.addView(im);
}

but when I try to add a fragment instead of an ImageView to the frameLayout the code compiles perfectly but the desired fragment doesn't appear after the onClickListener() method is called. I checked the onCreateView() method of the fragment and it returns a proper view...

@Override
public void onClick(View button) {
    ServerDialogFragment serverDialog = new ServerDialogFragment();
    FragmentTransaction addDialog = getSupportFragmentManager().beginTransaction();
    addDialog.add(DETAIL_CONTENT_FRAME, serverDialog);
    addDialog.commit();
}

Do you have an answer to this ?

PS: I once tried adding fragments into other fragments and it worked, but they were simple fragments only holding ImageViews.

NemoOudeis
  • 332
  • 3
  • 15
  • Possible duplicate of [Fragment Inside Fragment](http://stackoverflow.com/questions/6672066/fragment-inside-fragment) – Suragch Sep 14 '16 at 14:03

1 Answers1

1

Fragments inside of other fragments is not supported at this time. See:

Community
  • 1
  • 1
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491