There are three different ways to get layoutinflater, so what's the difference between these three ways?
Source:
① Layoutinflater Inflater = layoutinflater.from (context); (Layoutinflater Class)
<span style= "FONT-SIZE:14PX;" >public static Layoutinflater from (context context) { Layoutinflater layoutinflater = (layoutinflater) Context.getsystemservice (context.layout_inflater_service); if (Layoutinflater = = null) { throw new Assertionerror ("Layoutinflater not Found.") ; return layoutinflater; } </span>
② layoutinflater inflater = Getlayoutinflater (); (activity Class)
<span style= "Font-size:14px;color: #330033;" >public Layoutinflater Getlayoutinflater () { return GetWindow (). Getlayoutinflater (); </span>
Public Phonewindow (Context context) { super (context); Mlayoutinflater = Layoutinflater.from (context); }
③ Layoutinflater inflater = (layoutinflater) context.getsystemservice(context.layout_inflater_ SERVICE); (activity Class)
<span style= "Font-size:14px;color: #330033;" > public static final String Layout_inflater_service = "Layout_inflater";</span>
ps:use with getSystemService(java.lang.String) To retrieve a android.view.LayoutInflater For inflating layout resources in this context.
From the source, three ways in essence are the same, ② is called ① method, and ① is called ③. Java is very interesting is such a tune to the tune, give a person a specious feeling.
For the Getsystemservice class, we can see a lot of service available in the source code:
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 an application Power_service (Powermanger) Service Alarm_service of power supply (Alarmmanager)Alarm Clock Service Notification_service (Notificationmanager)Service Keyguard_service for status bar (Keyguardmanager)Keypad Lock Service Location_service (Locationmanager)Location of the service Search_service (Searchmanager)Search for service Vebrator_service (Vebrator)Mobile phone Shake service Connectivity_service (Connectivity)Network-connected service Wifi_service (Wifimanager)WiFi Service Telephony_service (Teleponymanager)Telephone service
Not to be continued
Android Layoutinflater three ways to analyze