Android Programming – setContentView()

setContentView() is a very important function when it comes to programming with Android.

One has to understand its use completely to work with Android UserInterface.

Basically what this function does is display the Layout created thorugh XML or the Dynamically created layout view in the Screen.


Syntax –

For an XML Layout –


where showexcer.xml is your xml file.

For Dynamically created Java View/Layout

View v1=new View(this);

Similarly a dynamically created layout can be dispalyed using setContentView();

  • setContentView is amethod of Activity class. So to call you the class should be a subclass of Activity class.