android - "The specified child already has a parent" How can I remove view from AlertDialog -


i inflating linearlayout alertdialog. works fine if dismis , launch again gives me following error

java.lang.illegalstateexception: specified child has parent. must call removeview() on child's parent first.

in contructor:

infowindow = (linearlayout) ((activity) context).getlayoutinflater().inflate(r.layout.map_info_content, null); 

later:

protected boolean ontap(int index) {         builder dialog = new alertdialog.builder(context);         dialog.setview(infowindow);         dialog.show();         return true;     } 

i have tried keep dialog in memory , setting it's view null didn't fix problem

you cannot re-use inflated views in android once you've added them parent viewgroup. @ side, you're trying reuse inflated view in dialog. solve problem, inflate view in alertdialog class itself.

i'd recommend create separate class it. here's how oncreatedialog method like:

public dialog oncreatedialog(bundle savedinstance){      // create new dialog builder     alertdialog.builder builder = new alertdialog.builder(mcontext);      // dialog view inflate     view view = getactivity().getlayoutinflater()                                 .inflate(r.layout.map_info_content, null);      // sets view of our dialog     builder.setview(view);      // create , return dialog     return builder.create(); } 

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -