Android Layoutinflater dynamically Add delete view

Source: Internet
Author: User

I want to implement click on a button (or other event) to add or remove view, find the Layoutinflater this class online. here are some of my own experiences:Android official online Layoutinflater's api:http://developer.android.com/reference/android/view/layoutinflater.html1. Add view

LinearLayout mylayout = ( linearlayout ) Findviewbyid ( R. ID. My_layout) ; //Mylayout is the root layout of my activity's interface

View Hiddenview = Getlayoutinflater (). Inflate (R.layout.hidden_view, mylayout, false); Hiddenview is a hidden view,

Import from Hidden_view.xml file

Mylayout.addview (Hiddenview);

2. Delete View

View Hiddenview = Findviewbyid ( R. ID. Hidden_layout ) ; //Hidden_layout is root layout in hidden_view.xml

if (null! = Hiddenview) {

ViewGroup parent = (ViewGroup) hiddenview.getpatent ();

Parent.remove (Hiddenview);

}

Android Layoutinflater dynamically Add delete view

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.