0% found this document useful (0 votes)
29 views7 pages

Exp 4

Uploaded by

Sidharth Thakur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views7 pages

Exp 4

Uploaded by

Sidharth Thakur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

Experiment:- 4

Student Name: Nikhil Kumar UID: 20BCS1817


Branch: BE-CSE Section/Group: 20BCS-DM-716/B
Semester: 6th Subject Code: 20CSP-356
Subject Name: MAD Lab
Date of Performance: 30-03-2023

Aim/Overview of the practical:-


Create an application that takes the name from a text box and shows hello message
along with the name entered in text box, when the user clicks the OK button.

Objective:-
To create an android application with text box and button

Steps:
1. Create a New Project
2. Add the App Widget to the Project. Right-Click on the app, move the cursor
to new, find the “Widget” option at the end, select it.
3. Specify the required properties for the widget such as min. width and
height, config file and preferred language, etc, and proceed. Files are
automatically generated.
4. Create Code according to app requirements.
5. Select your device and run the code.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

CODE:-

xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_height="match_parent"
tools:context=".MainActivity">

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_height="match_parent"
android:background="#FFFF8D"
tools:context="com.example.akshay.mrcet.MainActivity">

<TextView android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:text="NAME"
android:textSize="20sp"
android:layout_margin="20dp"/>

<TextView android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp" android:text="PASSWORD"
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

android:layout_marginTop="38dp"
android:layout_below="@+id/textView"
android:layout_alignLeft="@+id/textView"
android:layout_alignStart="@+id/textView"/>

<EditText android:id="@+id/editName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"

android:hint="Enter Name"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="5dp"
android:layout_alignLeft="@+id/editPassword"
android:layout_alignStart="@+id/editPassword"/>

<EditText android:id="@+id/editPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10" android:hint="Enter
Password"
android:inputType="textPassword"
android:layout_alignBottom="@+id/textView2"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="18dp"
android:layout_marginEnd="18dp"/>
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

<Button android:id="@+id/buttonSubmit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"

android:layout_below="@+id/textView2"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:text="SUBMIT"/>

<Button android:id="@+id/buttonReset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RESET"
android:layout_alignBaseline="@+id/buttonSubmit"
android:layout_alignBottom="@+id/buttonSubmit"
android:layout_centerHorizontal="true"/>

<TextView android:id="@+id/tvResult"
android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="143dp"
android:textSize="30sp"/>
</RelativeLayout>
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

</androidx.constraintlayout.widget.ConstraintLayout>

java:
package com.example.myapplication;

import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View; import
android.widget.Button; import
android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {


// These are the global variables
EditText editName, editPassword;
TextView result;
Button buttonSubmit, buttonReset;

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

editName = (EditText) findViewById(R.id.editName);


editPassword = (EditText) findViewById(R.id.editPassword);
result = (TextView) findViewById(R.id.tvResult);
buttonSubmit = (Button) findViewById(R.id.buttonSubmit);
buttonReset = (Button) findViewById(R.id.buttonReset);
/*
Submit Button
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

*/
buttonSubmit.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
String name = editName.getText().toString();
String password = editPassword.getText().toString();

result.setText("Name:\t" + name + "\nPassword:\t" + password );

}
});

/*
Reset Button
*/

buttonReset.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
editName.setText("");
editPassword.setText("");
result.setText("");
editName.requestFocus();
}
});
}}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

Output:

You might also like