ViewPager 切换报错

来源:互联网 发布:在线自动配色软件 编辑:程序博客网 时间:2024/05/08 00:20

 java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first. 

在adapter里如下面代码这么写即可解决

@Override

public Object instantiateItem(ViewGroup view, int position) {
if(list.get(position).getParent()==null){
view.addView(list.get(position));
}else{
((ViewGroup)list.get(position).getParent()).removeView(list.get(position));
              view.addView(list.get(position));
}
return list.get(position);

}


0 0