Transferred from: http://blog.csdn.net/andypan1314/article/details/6715928
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:
[HTML]View Plaincopy
- 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.
[HTML]View Plaincopy
- 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
Android Inflate () method uses