The specified child already has a parent. You must call removeView() on the child's parent first.错误

来源:互联网 发布:大数据营销案例沃尔玛 编辑:程序博客网 时间:2024/06/05 19:53

The specified child already has a parent. You must call removeView() on the child's parent first.经常会在我们removeView时出现,很是糟心:

因为有时候不确定view的parent对象。解决方案:

if(view.getParent()!=null){            ((ViewGroup)view.getParent()).removeView(view);        }

这样view对象就能remove掉,并且不会报空指针~

0 0
原创粉丝点击