0% found this document useful (0 votes)
2 views

pr9 - Copy

The document contains an XML layout for an Android application that includes user input fields for Name, Age, Branch, and Semester, along with a Login button. The corresponding Java code defines a MainActivity that initializes these fields and displays Toast messages with the entered information upon clicking the Login button, before starting a new activity. The layout is designed using a RelativeLayout to position the elements appropriately on the screen.

Uploaded by

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

pr9 - Copy

The document contains an XML layout for an Android application that includes user input fields for Name, Age, Branch, and Semester, along with a Login button. The corresponding Java code defines a MainActivity that initializes these fields and displays Toast messages with the entered information upon clicking the Login button, before starting a new activity. The layout is designed using a RelativeLayout to position the elements appropriately on the screen.

Uploaded by

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

XML file

<?xml version="1.0" encoding="utf-8"?>


<RelativeLayout xmlns:android="http://schemas.a ndroid.com/apk/res/android"

xmlns:app="http://schemas.andro id.com/apk/res-auto"

xmlns:tools="http://schemas.andr oid.com/tools"
android:layout_width="match_pa rent"

android:layout_height="match_p arent"
tools:context=".MainActivity">

<TextView android:id="@+id/Name"

android:layout_width="wrap_con
Maharashtra State Board of Technical Education 73
tent"

android:layout_height="wrap_co ntent"
android:text="Name"

android:layout_marginTop="40d p"

android:layout_centerHorizontal= "true"
android:textSize="20dp"
/>
<EditText android:id="@+id/Name_ET"

android:layout_width="match_pa rent"

android:layout_height="wrap_co ntent"
android:ems="10"

android:inputType="textPersonN ame"
android:layout_centerHorizontal= "true"

android:layout_below="@+id/Na me_ET"
android:textSize="20dp"
/>
<EditText android:id="@+id/Age_ET"

android:layout_width="match_pa rent"

android:layout_height="wrap_co ntent"
android:ems="10"

android:inputType="textPersonN ame"

android:layout_marginTop="20d p"

android:layout_below="@+id/Age "

android:layout_below="@+id/Na me"

android:layout_marginTop="20d p"
/>
<TextView android:id="@+id/Age"

android:layout_width="wrap_con tent"

android:layout_height="wrap_co ntent"
android:text="Age"

android:layout_marginTop="40d p"
/>
<TextView android:id="@+id/Branch"

android:layout_width="wrap_con tent"

android:layout_height="wrap_co ntent"
android:text="Branch"

android:layout_marginTop="40d p"

android:layout_centerHorizontal= "true"

android:layout_below="@+id/Age
_ET"
android:textSize="20dp"

/>
<EditText

android:id="@+id/Branch_ET"

android:layout_width="match_pa rent"

android:layout_height="wrap_co ntent"
android:ems="10"

android:inputType="textPersonN ame"

android:layout_marginTop="20d p"

android:layout_below="@+id/Bra nch"
/>
<TextView android:id="@+id/Semester"

android:layout_width="wrap_con tent"

android:layout_height="wrap_co ntent"
android:text="Semester"

android:layout_marginTop="40d p"

android:layout_centerHorizontal= "true"

android:layout_below="@+id/Bra nch_ET"
android:textSize="20dp"
/>
<EditText
android:id="@+id/Semester_ET"

android:layout_width="match_pa rent"

android:layout_height="wrap_co ntent"
android:ems="10"

android:inputType="textPersonN ame"

android:layout_marginTop="20d p"

android:layout_below="@+id/Se mester"
/>
<Button android:id="@+id/Login"

android:layout_width="wrap_con tent"

android:layout_height="wrap_co ntent"
android:text="Login"

android:layout_below="@+id/Se mester_ET"

android:layout_marginTop="40d p"

android:layout_centerHorizontal= "true"
/>

<TextView android:id="@+id/Login"

android:layout_width="wrap_con tent"

android:layout_height="wrap_co
ntent"
android:text="Student Login" android:textSize="40dp"

android:layout_centerHorizontal= "true"

android:textColor="@color/teal_2 00"
/>
</RelativeLayout>

Java File:
package com.example.exp10_2;

import androidx.appcompat.app.AppCo mpatActivity;


import android.content.Intent; import android.os.Bundle; import
android.view.View; import android.widget.Button; import android.widget.EditText;
import android.widget.Toast; import android.widget.ToggleButton;

import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

EditText name_et,age_et,branch_et,sem_et
;
String Username,Age,Branch,Semester;
Button login;

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceStat
e);

setContentView(R.layout.activity_ main);

name_et=findViewById(R.id.Nam e_ET);

age_et=findViewById(R.id.Age_E T);

branch_et=findViewById(R.id.Br anch_ET);

sem_et=findViewById(R.id.Semes ter_ET);
login
=findViewById(R.id.Login);

login.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View
v) {

Username=name_et.getText().toSt ring();

Age=age_et.getText().toString();

Branch=branch_et.getText().toStr ing();

Semester=sem_et.getText().toStrin g();

Toast.makeText(MainActivity.this
,"Welcome "+Username
,Toast.LENGTH_SHORT).show()
;

Toast.makeText(MainActivity.this
,"Age "+Age
,Toast.LENGTH_SHORT).show()
;

Toast.makeText(MainActivity.this
,"Branch "+Branch
,Toast.LENGTH_SHORT).show()
;

Toast.makeText(MainActivity.this
,"Semester "+Semester
,Toast.LENGTH_SHORT).show()
;

Intent intent=new
Intent(MainActivity.this,Empty_A ctivity.class);
// intent.putExtra("username",User name);
startActivity(intent);

}
});

}
}

You might also like