What is Inflater in Android
To summarize what the LayoutInflater Documentation says... A
LayoutInflater
is one of the Android System Services that is responsible for taking your XML files that define a layout, and converting them into View
objects. The OS then uses these view objects to draw the screen.
Typically, you don't ever need to directly use a LayoutInflater. Android does most of the layout inflation for you when you call
setContentView()
in the onCreate()
method of your activity. So you, as the programmer, are responsible for making sure the views are inflated. Now you want to inflate views in the context of a ListView. The Adapter class can do the inflation for you if you do not want to customize each item. But if you want to customize the views shown in a list, you will have to manually inflate each view with the LayoutInflater, since there is no other existing method you can use.
There is no advantage to using it. You are required to use a LayoutInflater in some shape or form to inflate your static XML layouts.
Alternatively, you could create views dynamically with java code. However, you would need to call methods to set each property for the view by hand. In my opinion, it is easier to use the XML/inflation process. In addition, Android pre-processes your XML files at build time, so this results in a faster execution time.
Comments
Post a Comment