开发者

Problem putting a fragment into another fragment

开发者 https://www.devze.com 2023-04-02 15:00 出处:网络
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 t

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);
    ImageVi开发者_运维百科ew 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.


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

  • Fragment Inside Fragment
  • Fragments within Fragments
  • Android: Can you nest Fragments?
0

精彩评论

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

关注公众号