You are on page 1of 4

Computer Laboratory Activity #1:

Objective: Mobile Application Development using Android Studio that will input information using
EditText, TextView and display all.

1. Create an Android Project.


 Go to File Menu, Select New-New Project.
 Choose Empty Activity (under Phone and Tablet Project)
 Click Next.
 Name of Application:inputdetails(or any project name), then select Java on
Language selection.
 Click Finish.
2. Add TextView for Label.
 Drag and drop two TextView from widget(One label for input and for output)
3. Add EditText for UserInput
 Similarly drag EditText box from the list of Text Palette.
4. Add Button for User Submission
 To add button, drag and drop button from the widget.
5. Button Handler
 Everything is done with the design view. Let’s add Listener into source file(java0
Which will be in path(C:\Users\ACER\AndroidStudioProjects\InputDetails\app\src\main\java
\com\example\inputdetails\MainActivity.java)
6. Read input from EditBox Control
 User input is read by instances of form controls. The input entered by the user
Is read by getText() method that is called by Editbox instance.

Button myButton;
EditText txtinput;
TextView txtoutput;

txtinput = (EditText)findViewById(R.id.editText2);
txtinput.getText().toString();

 And then the instance of Textview is created to show the welcome message.
This will be done by the following codes:

txtoutput = (TextView)findViewById(R.id.textView3);
txtoutput.setText("Here are your
Details:\nName:"+txtinput.getText().toString());
Sample Source Code for Input and Display Data using EditText, TextView and Button

package com.example.inputdetails;

import androidx.appcompat.app.AppCompatActivity;

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

import org.w3c.dom.Text;

public class MainActivity extends AppCompatActivity


{
Sample Design View
Button myButton;
EditText txtinput;
TextView txtoutput;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

myButton = (Button)findViewById(R.id.button2);

myButton.setOnClickListener(new View.OnClickListener()
{
public void onClick(View view){
txtinput = (EditText)findViewById(R.id.editText2);
txtoutput = (TextView)findViewById(R.id.textView3);
txtoutput.setText("Here are your
Details:\nName:"+txtinput.getText().toString());
}

});

}
}
Sample Output View

Create an android application that will get Student


No.,Student Name, Course,Year and Section then Display all.

You might also like