首页 > 代码库 > AlertDialog The specified child already has a parent. You must call removeView() on the child's parent first.

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

点击AlertDialog 关闭之后再点击报错:

 

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

 

意思是这个子view 已经有个父view了,你现在要使用的话,必须把子view从父view中移除掉。

解决:

 加上 : ((ViewGroup) view.getParent()).removeView(view);  

 

 

builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {

 

((ViewGroup) layout.getParent()).removeView(layout);
}
});

 

 
 

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