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.

3 Responses

  1. I have external site that host the jsp and Android app that uses the view in one tab. I want to call jsp using loadUrl method by callling another activity and then get the result of that jsp (which is content management string) in original activity

  2. Yes so simply define the load url method in your another activity,where you want to retrieve the jsp data.And in order to pass the data from your external view(jsp page) to your another activity simply parse the data in that jsp page in whatever format it is.

  3. very old post, but still helpful immensely. thank you

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: