Android about inflate root parameter

Source: Internet
Author: User

Recently, when using the view inflate (context context, int resource, ViewGroup root) method, a bit of trouble was encountered on the third parameter root.

Custom columns are typically loaded when you write the adapter of a ListView

NULL );... viewgroup.addview (imagelayout);

If this is the case, there may be a problem when calling Imagelayout

// add layout to ViewGroup when inflate View imagelayout = Inflate (GetContext (), R.layout.item_album_pager, ViewGroup);

This is because the Inflate method returns the root of the view when the third parameter root is not empty, and when root is empty, the node that is the loaded layout is returned. Look at the API explanation:

New  from if  is   for A is is the root of the inflated XML file.

I was in the Viewpager of the adapter, using the root is not empty inflate method, return to layout error.

@Override          Public int position) {            = Inflate (GetContext (), R.layout.item_album_pager, viewgroup);                        ....             // this actually returns the entire viewgroup, causing an error.            return imagelayout;        }

Here is an example of the inflate method that comes with the view class, which essentially invokes the Layoutinflater Class View inflate (int resource, ViewGroup root) method.

 Public Static int resource, ViewGroup root) {        = Layoutinflater.  from (context);         return Factory.inflate (resource, root);    }

Android about inflate root parameter

Related Article

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.