0
为了避免声明布局xml,我正在将一个片段添加到活动中。我在做以编程方式使用单个片段初始化FragmentActivity
@Override
protected void onCreate(Bundle arg0) {
super.onCreate(arg0);
getSupportFragmentManager().beginTransaction()
.add(android.R.id.content, new mFragment()).commit();
}
但它与崩溃:
java.lang.IllegalStateException: The specified child already has a parent.
You must call removeView() on the child's parent first.
是否有避免这种错误,或者我必须收回之前的内容布局,并删除他们所有的意见很短的形式?由于
编辑mFragment代码:
public class mFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View result= inflater.inflate(R.layout.activity_main, container);
return result;
}
}
你的片段类'mFragment'的邮政编码 – waqaslam
邮政编辑;)。 – Addev
看到这个问题。 http://stackoverflow.com/questions/11973016/add-multiple-fragments-programmatically/11973156#11973156 – DeeV