What is the function of setcontentview and inflatter in Android Studio?

Rlogical Techsoft
2 min readJan 22, 2021
Android Studio reference by Google

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.

  1. setContentView(int resourceId)
  2. setContentView(View view)
  3. 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.

reference: google.com

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.

--

--

Rlogical Techsoft

Web & Mobile App Development Company. Expertise in Mobile App, PHP, ASP .NET, MVC 5 (Razor), MongoDB, NodeJS, AngularJS, ReactJS, Windows App, POS, Scraping.