在我的 Activity 上动态添加片段
我正在使用片段,当我在左侧片段上选择某些内容时,我希望我的主要活动创建一个右侧片段。
所以我这样做是为了在 FrameLayout 上添加我的 Fragment :
//add a fragment
FluxDetailFragment myFragment = new FluxDetailFragment();
fragmentTransaction.add(R.id.frameLayout3, myFragment);
fragmentTransaction.commit();
但我收到此错误:
02-02 15:34:03.104: E/AndroidRuntime(14794): java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
我必须先删除我的 FrameLayout 视图吗?还是另一种看法?怎么办呢?
I'm using fragments and when I select something on my left fragment, I want a right fragment to be created by my main activity.
So I did this to add my Fragment on a FrameLayout :
//add a fragment
FluxDetailFragment myFragment = new FluxDetailFragment();
fragmentTransaction.add(R.id.frameLayout3, myFragment);
fragmentTransaction.commit();
But I get this error :
02-02 15:34:03.104: E/AndroidRuntime(14794): java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
Do I have to remove my FrameLayout view before? Or another view? How to do so?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了解决我的问题,我这样做了:
相反,我这样做了:
attachToRoot 必须设置为 null 才能工作。
To solve my problem, I had this :
Instead of that, I did this :
attachToRoot must be set to null to work.