What is the function of setcontentview and inflatter in Android Studio?
setContentView(View) is a method exclusively available for Activity.
Internally it calls the setContentView(View) of Window. This method sets the activity content to an explicit view.
SetContentView() method is 3 types.
- setContentView(int resourceId)
- setContentView(View view)
- setContentView(View view, android.view.ViewGroup.layoutparams params)
This view is placed directly into the activity’s view hierarchy. Calling this function “locks in” various characteristics of the window that can not, from this point forward, be changed. Hence it is called only once.
LayoutInflater is used to instantiate layout XML file into its corresponding View objects.
public abstract class LayoutInflater
extends Object
java.lang.Object ↳android.view.LayoutInflater
Basically the purpose is to create view objects at runtime depending on the requirement.
Best example is the AdapterViews like ListView, Spinner etc, where a single view object corresponding to single record is created at run time depending on the number of records.
Learn more here LayoutInflater:https://developer.android.com/reference/android/view/LayoutInflater
If you have more questions regarding android app development services then contact to our Hire dedicated Android developers now.