java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
代码如下:在编写fragment的过程中
public class DetailFragment extends Fragment {
BookContent.Book book;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View root=inflater.inflate(R.layout.fragmentdetail, container);
if(book!=null){
((TextView)root.findViewById(R.id.book_title)).setText(book.title);
System.out.println(book.title);
((TextView)root.findViewById(R.id.book_desc)).setText(book.detail);
}
return root;
}
其中通过View root=inflater.inflate(R.layout.fragmentdetail, container);获得view为子控件,不能填充fragment容器需要解除与父空间的关系,所以要调用inflate的
View root=inflater.inflate(R.layout.fragmentdetail, container,false);//第三个参数是否解除与父控件之间的联系