Android own Definition dialog box and the specified child already have a child problem

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.