What is Inflater?
To summarize what the LayoutInflater Documentation says ... A LayoutInflater is one of the Android system services that is responsible for receiving your XML files, which define the layout, and turning them into View objects. The OS then uses these view objects to draw a screen.
I always had an ambiguity in why we need to use inflater in android, why are they used in android ListView for custom layout?
Usually you do not need to use LayoutInflater directly. Android does most of the layout inflation for you when you call setContentView() in the onCreate() method of your activity. Thus, you, as a programmer, are responsible for ensuring that opinions are inflated. . Now you want to inflate the views in the context of the ListView. The Adapter class can do inflation for you if you don't want to customize each element. But if you want to customize the views shown in the list, you will have to manually inflate each view with LayoutInflater, since there is no other existing method that you can use.
What is the advantage of using Inflater?
It makes no sense to use it. You must use LayoutInflater in some form or form to inflate your static XML layouts.
Alternatively, you can dynamically create views using java code. However, you will need to call methods for each property for manual submission. In my opinion, itβs easier to use the XML / inflation process. In addition, Android preprocesses your XML files at build time, so this leads to faster execution time.
source share