How to Inflate a Layout

Defing your UI in XML and inflating it is the preferred way of implement your user interfaces (UIs), as it neatly decouples your application logic from your UI design.

1. In the MainActivity.java file, add the line below to the onCreate method. This will inflate, or display, a layout named main.xml that is located in the res/layout folder.

setContentView(R.layout.main);

2. Compile and run!

Resources: