问题把一个片段到另一个片段 [英] Problem putting a fragment into another fragment

查看:157
本文介绍了问题把一个片段到另一个片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图把一个片段成的FrameLayout通过FragmentManager和FragmentTransaction(从android.support.v4.app)另一片段中。容器片段有一个按钮,并在上面一个TextView,并在底部的FrameLayout(我编程方式创建的布局和我不想与所有的伤害你的眼睛)。该CreateView的()工作得很好,我CANN在容器的底部访问的FrameLayout,并添加或通过

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);
}

但是当我尝试到的ImageView的增加,而不是片段向的FrameLayout的code编译完美,但onClickListener()方法被调用后所需片段不会出现。我查了片段的onCreateView()方法,它返回一个正确的看法...

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();
}

你有一个答案?

PS:我曾经尝试添加片段到其他片段,和它的工作,但他们是简单的片段只持有ImageViews

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 Fragmengt
  • Fragments within Fragments
  • Android: Can you nest Fragments?

这篇关于问题把一个片段到另一个片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆