0

我正在尝试在对话框上使用自定义视图。我不断收到错误

07-09 18:03:38.740: E/AndroidRuntime(22032): java.lang.IllegalStateException:
The specified child already has a parent. You must call removeView() 
on the child's parent first.

这是我的代码

LayoutInflater inflater = getLayoutInflater();
    View dialoglayout = inflater.inflate(R.layout.activity_mine1,
        (ViewGroup) findViewById(R.layout.mine1));
    mine1 = new AlertDialog.Builder(this);
    mine1.setView(dialoglayout);
    mine1.show();

我该如何解决?(大概我所要做的就是删除视图。)

4

1 回答 1

0

尝试这个;

if(dialoglayout.getParent()!=null){
      ((ViewGroup) dialoglayout.getParent()).removeView(dialoglayout);
}

您可以使用此删除视图。

于 2016-11-07T09:35:32.267 回答