我正在尝试在Dialog上使用自定义视图。我一直收到错误
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();
我该如何解决这个问题? (据推测,我所要做的就是删除视图。)
答案 0 :(得分:0)
试试这个;
if(dialoglayout.getParent()!=null){
((ViewGroup) dialoglayout.getParent()).removeView(dialoglayout);
}
您可以使用此功能删除视图。