1

我正在使用片段,当我在左侧片段上选择某些内容时,我希望我的主要活动创建一个右侧片段。

所以我这样做是为了在 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 视图吗?还是另一种看法?怎么做?

4

1 回答 1

1

为了解决我的问题,我有这个:

View result = inflater.inflate(R.layout.view2);

取而代之的是,我这样做了:

View result = inflater.inflate(R.layout.view2, null);

attachToRoot 必须设置为 null 才能工作。

于 2012-02-06T17:46:02.083 回答