有关于子控件填充容器的异常说明
2014-09-01 17:03
253 查看
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);//第三个参数是否解除与父控件之间的联系
代码如下:在编写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);//第三个参数是否解除与父控件之间的联系
相关文章推荐
- 关于VS.NET中窗体设计器初始化控件引发的设计时异常
- 关于MSCOMM控件的一些说明第1/2页
- 关于控件Visible属性的说明
- 关于11.21博客访问异常的说明
- 关于漂亮控件的说明 收藏
- 关于FlexCell控件的SelectionMode属性(选择模式)的说明
- 关于CS模式下,控制一个容器内控件的值问题
- 关于DAO中add方法异常抛出的说明
- Silverlight关于容器与子控件的加载与事件触发
- 关于PB中ddlb控件制作动态增量查询的说明.
- 关于WebBrowser2控件API函数说明
- Web Office开发中关于NTKO控件说明
- 关于控件Visible属性的说明
- 关于UDP消息服务抛出“远程主机强迫关闭了一个现有的连接”的异常说明及处理方法
- [转] 关于MSCOMM控件的一些说明
- 看《C++ STL》发现的关于异常说明的问题
- 关于MSCOMM控件的一些说明
- 关于MSCOMM控件的一些说明
- WinForm设计时异常】关于VS.NET中窗体设计器初始化控件引发的设计时异常
- 关于漂亮控件的说明