Android – Creating First New Project – 2

This tutorial is the continuation of this tutorial Android – Creating First New Project – 1. In the previous tutorial we learnt to create a new Android Project. Here In this tutorial first of all we will learn about the project structure and then we will learn about the coding in Java and XML and run our app. 

After creating our new project we will get the project structure as shown in image.

Now we will learn about some basic files in project structure.

  • src – Directory for your app’s main source files. By default, it includes an Activity class that runs when your app is launched using the app icon.
  • gen – It contains auto generated code like This files creates a link between your activity file (java file) and layout file (xml file).
  • res –  It contains several sub directories for app resources –
    • drawable-hdpi/ldpi/mdpi/xhdpi/xxhdmi –Directory for drawable objects (such as bitmaps) that are designed for high-density (hdpi) ,low-density (ldpi), medium-density (mdpi), extra high-density (xhdpi) and double extra high-density (mdpi) screens.
    • Layout – Directory for files that define your app’s user interface.
    • Values – Directory for other various XML files that contain a collection of resources, such as string definitions.
  • Manifest file – The manifest file describes the fundamental characteristics of the app and defines each of its components.

Here we are going to make an app in which there will be three objects – EditText, TextView and Button. EditText is just a text box where we input something, TextView is just a lable where we can display any kind of text, and you must be familiar about the work of Button. Here we will enter any text inside the EditText and click on the button, after clicking the text that we have entered must be printed on the TextView. So this is what we are going to make in this app. So let’s start !!

1. First of all we will create our layout. So go to res –> layout –> activity_main.xml and double click on this file.

2. Now copy and paste the code there as given below.

<LinearLayout xmlns:android=""
 tools:context=".MainActivity" >

 android:hint="Enter Text" >

<requestFocus />

 android:text="Print" />

 android:textAppearance="?android:attr/textAppearanceLarge" />


3. Now save the file with combination of ctrl+s and close the file.

4. So now our layout will look like this as shown in figure.

5. Now go to src –> com.apptronix.firstproject –> and open this file.

6. Now copy and paste the code there as given below.

package com.apptronix.firstproject;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends Activity {

// Declare variable for each object in xml file
 // ctrl+space for suggestion

Button b1;
 EditText e1;
 TextView t1;

 protected void onCreate(Bundle savedInstanceState) {

// linking each variable with id on xml

b1 = (Button) findViewById(;
 e1 = (EditText) findViewById(;
 t1 = (TextView) findViewById(;


// create method for onclick on button

public void click(View v) {
 String name = e1.getText().toString(); // fetching text from edittext
 // and converting it into string

t1.setText(name); // printing the text from editext to textview

e1.setText(""); // clearing the edittext


7. Now save the file with combination of ctrl+s and close the file.

8. Now we have to run the file. Right click on project, go to Run As –> Android Application.

Complete Video Tutorial :

Thank you for visiting our tutorial. If you have any doubts or queries regarding this, you can comment below in our comment section. Don’t forget to share the tutorial if you like it.

Previous Part : Android – Creating First New Project – 1

© Copyright 2016 – Apptronix Technologies. All Rights Reserved. ISO 9001:2015 Certified