Android ListFragment自定义view报错解决方案

来源:互联网 发布:达思数据恢复官网 编辑:程序博客网 时间:2024/05/30 07:14

Android 3.0后引入了ListFragment,默认情况下Android已经给我们提供了一些简单的交互,但是那个进度条太丑了。

想自己定制下布局,在onCreateView里面inflat自定义layout的时候一直宝这个错‘The specified child already has a parent. You must call removeView() on the child's parent first.’ 各种尝试后发现inflat的第三个参数必须是false,

inflater.inflate(R.layout.list_layout, container, false);
记得以前不传第三个参数默认是false,今天总算又被坑了一回。

        第三个参数的意思是inflat出来的view是否附在rootview上面(这里的container)attachToRootWhether the inflated hierarchy should be attached to the root parameter? If false, root is only used to create the correct subclass of LayoutParams for the root view in the XML.


0 0