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 に答える