The specified child already has a parent. You must call removeView"

  android动态加载fragment,会报上面那个错误,代码中没有动态addview的代码,半天没能找到问题。其实问题在onCreateView方法中inflater.inflate(R.layout.content_fragment, container); 函数发生错误。

inflater.inflate这个方法有两个参数的方法,也有三个参数的方法,两个参数的方法中最后一个参数系统自动帮忙填充为true。修改上面那个异常,只需使用三个参数的方法,最后一个参数使用FALSE即可。

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325184337&siteId=291194637