![解决alaert.builder二次调用报错的bug 解决alaert.builder二次调用报错的bug](https://image.shishitao.com:8440/aHR0cHM6Ly9ia3FzaW1nLmlrYWZhbi5jb20vdXBsb2FkL2NoYXRncHQtcy5wbmc%2FIQ%3D%3D.png?!?w=700&webp=1)
报错的代码是:
The specified child already has a parent. You must call removeView() on the child's parent first
大致是说你的弹出框中的view已经绑定了一个paren,就是你的弹出框。当你再次调用显示的时候。他以为你又要绑定到一个新的窗体上去。
解决办法是每次显示之前都又一次填充设置view.例如以下:每次点击的时候调用:
public void startClick(View view){
LayoutInflater inflater = LayoutInflater.from(getApplication());
mFloatLayout = (LinearLayout)inflater.inflate(R.layout.province_item, null);
builder = new AlertDialog.Builder(MainActivity.this)
.setView(mFloatLayout);
ad = builder.show();
}