First, let's take a look at the layouinflater class: instantiate a layout XML file as a view object. Instead of using it directly, he uses getlayoutinflater () or getsystemservice (string) to obtain the standard layoutinflater instance. The instance has connected the context and configured the running device correctly. For example, [Java] view plaincopylayoutinflater Inflater = (layoutinflater) context. getsystemservice (context. layout_inflater_service); Public View inflate (INT resource, viewgroup root) since: API Level 1 inflate a new view hierarchy from the specified XML resource. throws inflateexception if there is an error. parametersresource ID for an XML layout resource to load (e.g ., r. layout. main_page) Root optional vie W to be the parent of the generated hierarchy. returnsthe Root View of the inflated hierarchy. if root was supplied, this is the root view; otherwise it is the root of the inflated XML file. suppose there is such an XML file (guess_button.xml) Put into a buttontablelayout: [HTML] view plaincopy <? XML version = "1.0" encoding = "UTF-8"?> <Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: layout_width = "match_parent" Android: layout_height = "match_parent" Android: Orientation = "vertical"> <button Android: id = "@ + ID/newgustmutton" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: layout_weight = "1"/> </linearlayout> (guess_button.xml) [HTML] view plaincopy <tablelayout Android: Id = "@ + ID/buttontablelayout" Android: layout_width = "match_parent" Android: layout_height = "wrap_content" Android: layout_weight = "1" Android: stretchcolumns = "0, 1, 2"> <tablerow Android: Id = "@ + ID/tablerow0" Android: layout_width = "match_parent" Android: layout_height = "wrap_content" Android: Orientation = "horizontal"> </tablerow> <tablerow Android: Id = "@ + ID/tablerow1" Android: layout_width = "match_parent" Android: layout_height = "wrap_content" Android: Orientation = "horizontal"> </tablerow> <tablerow Android: Id = "@ + ID/tablerow2" Android: layout_width = "match_parent" Android: layout_height = "wrap_content" Android: Orientation = "horizontal"> </tablerow> </tablelayout> (main. the extended buttontablelayout defined in XML is also called buttontablelayout, that is, buttontablelayout = (tablelayout) findviewbyid (R. id. buttonlayout);) Now we can expand its first line: [Java] view plaincopylayoutinflater Inflater = (layoutinflater) context. getsystemservice (context. layout_inflater_service); button newguw.utton = (button) Inflater. inflater (R. layout. guess_button, null); // obtain the button newgustmutton. settext ("ABC"); // set the button text newguw.utton. setonclicklistener (gustmuttonlistener); // sets the listener (tablerow) buttontablelayout. getchildat (1); // Add newgustmutton to the first row of table. OK. The whole process is completed.