Layoutinflater is meant to be "extended" in Android, similar to Findviewbyid (), unlike Layoutinflater, which is used to obtain layout file objects, and Findviewbyid () is used to obtain specific controls. Layoutinflater is often used in the GetView method of Baseadapter to get the entire view and return.
Three ways to use Layoutinflate:
Method One:
Layoutinflater inflater = Layoutinflater.from (thisnull);
Method Two:
Layoutinflater inflater =null);
Method Three:
Layoutinflater inflater =null);
Simple example:
Public classLayoutinflateractivityextendsActivity {PrivateEditText et; PrivateButton btn; @Override Public voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); //The first of these methodsLayoutinflater Inflater = Layoutinflater.from ( This); View Layout= Inflater.inflate (R.layout.main,NULL); //The second method of//Layoutinflater inflater = Getlayoutinflater (); //View layout = inflater.inflate (R.layout.main, NULL); //The third method of//layoutinflater inflater = (layoutinflater) getsystemservice (Layout_inflater_service); //View layout = inflater.inflate (R.layout.main, NULL); //get specific controls and instantiateET =(EditText) Layout.findviewbyid (R.id.edittext); Et.setbackgroundcolor (Color.yellow); BTN=(Button) Layout.findviewbyid (R.ID.BTN); Btn.setbackgroundcolor (Color.cyan); //ShowSetcontentview (layout); }}
When you want to create a screen in Android, it is generally a new class, inheriting the activity class, and then using the Setcontentview method in OnCreate to load a well-defined interface in XML.
In fact, the activity inside the use of Layoutinflater to load the interface, through the Getsystemservice (Context.layout_inflater_service) method can be obtained a layoutinflater , and then use the inflate method to load the XML for layout, and for an interface that is not loaded or wants to be loaded dynamically, it needs to be loaded using inflate.
For an already loaded interface, you can use this interface to invoke the Findviewbyid method to get the sub-interface.
Another Getsystemservice () is an important API for Android, a method of activity that obtains the corresponding object according to the name passed in, and then translates it into the corresponding service object. The following describes the system's corresponding services.
Description of the object returned by the incoming name:
Window_service WindowManager manages the open Windows program Layout_inflater_service layoutinflater Gets the viewactivity_service defined in the XML Activitymanager managing the System state of the application Power_service Powermanger power supply Alarm_service Alarmmanager Alarm Clock Service Notification_service notificationmanager status bar service Keyguard_service Keyguardmanager Keypad lock Service Location_service locationmanager location services, such as Gpssearch_service Searchmanager Search service Vebrator_service vebrator phone Vibrate service connectivity_service Connectivity Network Connection service Wifi_ Service Wifimanager Wi-fi services Telephony_service teleponymanager Telephone service
Reprint Please specify source: http://www.cnblogs.com/yydcdut/p/3744877.html
Reference: HTTP://HI.BAIDU.COM/LAOCUI172/ITEM/03649BFCAEE761C4A835A2AC