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.
- 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