Problem: During Android Development, there are times when you encounter the same problem in different situations: thespecified child already has a parent. You must call Removeview () in the child's parent first. Log for example as seen in:
Analysis: Meaning that this particular Child already have a Parent , assuming you want to continue using it, you must first call the Removeview () method to remove its original parent, ability to continue your content.
Example: Clicking a button in the main activity pops up the dialog box that defines the view
First of all:
Etcontentview (R.layout.main
Second
Second: Click on the button to listen, click Function to invoke the dialog box function
1. handling of dialogs: Create a new Defview with a edittext (same as other controls)
<edittext android:id= "@+id/filename" android:layout_width= "match_parent" android:layout_height= "Wrap_content"/>
2. Because the control to invoke in the dialog box is not in the layout file Main.xml, we must first call the relevant function of the layout fill class to find the layout
LinearLayout def = (linearlayout) getlayoutinflater (). Inflate (r.layout.dialog_save_file, NULL);
3. Then locate the corresponding control in the layout:
Edttxtfilename = (EditText) Saveform.findviewbyid (r.id.filename);
Establishment of dialog box in 4.click function
Alertdialog.builder Builder = new Alertdialog.builder (this). Settitle ("Save sdcard/sign/"). SetIcon (r.drawable.save_ file). Setview (Def);//Add your own defined content to the dialog box
</pre><pre name= "code" class= "Java" > Last: In the dialog box itself, press the key to confirm or cancel the click Response to add:
((ViewGroup) saveform.getparent ()). Removeview (Def);
Android own Definition dialog box and the specified child already have a child problem