the specified child already has a parent

后端 未结 4 1727
梦如初夏
梦如初夏 2020-12-20 18:17

I created the AlertDialog using the builder. It shows when we call the show() method. I have the cancel button in that dialog. I can cance

4条回答
  •  庸人自扰
    2020-12-20 18:54

    Don't show the same dialog, create a new one.

    This is happening because you are trying to re-use the dialog which was already created (Probably at onCreate)and used once. There is no issue in reusing a dialog but as in the question the the specified child (the view) already has a parent (the dialog).You could either continue by removing the parent or you can create a new parent like :-

    alertDialog=new AlertDialog(Context);
    alertDialog.setView(yourView);
    alertDialog.show();
    

提交回复
热议问题