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

报错的代码是:

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();
}
上一篇:codeforces 342E :Xenia and Tree


下一篇:mybatis 异常Result Maps collection does not contain value for java.lang.String