解决alaert.builder二次调用报错的bug

来源:互联网 发布:淘宝app怎么换皮肤 编辑:程序博客网 时间:2024/06/05 07:09

报错的代码是:

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();}



1 0
原创粉丝点击