The basic usage of inflate, similar to the Findviewbyid

Source: Internet
Author: User

The inflate () function is to find out a layout of the XML definition, but only to find out and hide, not find the same time and display the function. One of the most recent projects I've been doing is that I've been confused for days.

There is also a method called Findviewbyid () similar to inflate () on Android, which can sometimes be used, but there are also differences

The difference is:

If you use other layout in your activity, such as dialog layout, and you want to set the contents of other components on this layout, you must use the inflate () method to find out the layout of the dialog box first, and then use the Findviewbyid () Find the other components above it. For example:

View view1=view.inflate (This, r.layout.dialog_layout,null);  Textviewdialogtv  =(TextView) View1.findviewbyid (R.ID.DIALOG_TV);  Dialogtv.settext (  "ABCD");  

Note: R.ID.DIALOG_TV is a component on the layout of the dialog box, and if the direct use of This.findviewbyid (R.ID.DIALOG_TV) will definitely be an error.


    1. View viewstub = ((viewstub) Findviewbyid (R.id.stubview)). Inflate ();

Inflate () or can be understood as "hidden expansion", hidden in view, inflate () just get control, but no size does not occupy space in the view, inflate () after a certain size, just out of the hidden state

The basic usage of inflate, similar to the Findviewbyid

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.