In layman's words, inflate is the equivalent of locating a layout defined in an XML.
Because if you use Findviewbyid () directly in an activity, the component in the layout of Setconentview () is the corresponding one.
So if you use other layout in your activity, such as the layout on the dialog, you also have to set the contents of the Layout on the dialog box (like picture ImageView, Text TextView), you have to use inflate () Find the layout of the dialog box first, and then use the layout object to find the components above it, such as:
Viewview=view.inflate (This,r.layout.dialog_layout,null);
textviewdialogtv= (TextView)view. Findviewbyid (R.ID.DIALOG_TV);
Dialogtv.settext ("ABCD");
If the component R.id.dialog_tv is a component on the dialog box, and you use This.findviewbyid directly (R.ID.DIALOG_TV), you will definitely get an error.
There are three ways to generate Layoutinflater:
Layoutinflaterinflater=layoutinflater.from (this);
Layoutinflaterinflater=getlayoutinflater ();
Layoutinflaterinflater= (Layoutinflater) This.getsystemservice (Layout_inflater_service);
Then call the inflate method to turn the XML layout file into view
layoutinflater layoutinflater = layoutinflater. from (Dialogactivity.this);
Get a custom dialog box
Final View dialogview = layoutinflater. Inflate (r.layout.dialog_login, NULL);
Publicviewinflate (Intresource,viewgrouproot,booleanattachtoroot)
In the view class, there are also inflate methods
Publicstaticviewinflate (Contextcontext,intresource,viewgrouproot)
Citation: http://android.tgbus.com/Android/tutorial/201104/348009.shtml
Android--inflate to find the layout defined in an XML