然后我在别的类中
contentFragment contentFragment1 = new contentFragment();完成各种代码后就报以下的错误了Caused by:java.lang.IllegalStateException:
The specified child already has a parent. You must call removeView() on the child's parent first.
异常说明:所用的子类已经在一个父类中View,必须在第一个父类移除显示(removeView)
也即是说你的view已经显示在一个view,如果你要显示在另一个view中,请在第一个view中removeView后才能显示其他view中
第一种解决方法:
把代码改成以下就能显示
public class contentFragment extends Fragment{ @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.content_layout,container,false); return view; } }第二中解决方法:
在父类view中调用removView();
