0% found this document useful (0 votes)
21 views2 pages

Module 4

The document contains code for an Android student registration activity. It includes an XML layout file with views like TextViews and EditTexts for collecting a student's name, roll number, phone number and email. It also has a button to register the student. The MainActivity class finds the views, sets an onClick listener for the button to get the data from the EditTexts and display a Toast message with the collected details.

Uploaded by

Smiley Smiley
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download as txt, pdf, or txt
0% found this document useful (0 votes)
21 views2 pages

Module 4

The document contains code for an Android student registration activity. It includes an XML layout file with views like TextViews and EditTexts for collecting a student's name, roll number, phone number and email. It also has a button to register the student. The MainActivity class finds the views, sets an onClick listener for the button to get the data from the EditTexts and display a Toast message with the collected details.

Uploaded by

Smiley Smiley
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1/ 2

//activity_main.

xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Student Details Registration"
android:textSize="24sp"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="20dp"/>

<EditText
android:id="@+id/etName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Name"
android:inputType="textPersonName"/>

<EditText
android:id="@+id/etRollNo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Roll Number"
android:inputType="number"/>
<EditText
android:id="@+id/etPhoneNo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Phone Number"
android:inputType="number"/>
<EditText
android:id="@+id/etEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Email"
android:inputType="textEmailAddress"/>

<Button
android:id="@+id/btnRegister"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Register"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"/>

</LinearLayout>

//MainActivity.java
package com.example.studentactivity;

import androidx.appcompat.app.AppCompatActivity;

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

import com.example.studentactivity.R;

public class MainActivity extends AppCompatActivity {


EditText etName, etRollNo,etPhoneNo,etEmail;
Button btnRegister;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etName = findViewById(R.id.etName);
etRollNo = findViewById(R.id.etRollNo);
etPhoneNo=findViewById(R.id.etPhoneNo);
etEmail=findViewById(R.id.etEmail);

btnRegister = findViewById(R.id.btnRegister);
btnRegister.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String name = etName.getText().toString().trim();
String rollNo = etRollNo.getText().toString().trim();
String PhoneNo=etPhoneNo.getText().toString().trim();
String Email=etEmail.getText().toString().trim();

// You can perform various operations with the data, such as


displaying it in a TextView or storing it in a database.
Toast.makeText(MainActivity.this, "Name: " + name + ", Roll Number:
" + rollNo + ", Phone No: " + PhoneNo +",Email:" + Email ,
Toast.LENGTH_SHORT).show();
}
});
}
}

//buildgradient2
dependencies {
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.6.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}

You might also like