What is setContentView(R.layout.main)?

android, layout

Solution

In Android the visual design is stored in XML files and each Activity is associated to a design.

setContentView(R.layout.main)

`R` means Resource

`layout` means design

`main` is the xml you have created under `res->layout->main.xml`

Whenever you want to change the current look of an Activity or when you move from one Activity to another, the new Activity must have a design to show. We call `setContentView` in onCreate with the desired design as argument.

Problem

I understand that it has to do with the App layout, but when do I have to use it? I tried to look for a link that explained this method, but I couldn't find it. Thank you in advance!

Original source