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

Module 5

The document contains an XML layout file and Java code for a student registration form Android app. The XML file defines a vertical linear layout containing edit text fields for a user's first name, last name, email, and phone number. It also contains a submit button. The Java code finds the edit text and button views, adds an on click listener to the button to validate and display the submitted information in a toast message.

Uploaded by

Smiley Smiley
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Module 5

The document contains an XML layout file and Java code for a student registration form Android app. The XML file defines a vertical linear layout containing edit text fields for a user's first name, last name, email, and phone number. It also contains a submit button. The Java code finds the edit text and button views, adds an on click listener to the button to validate and display the submitted information in a toast message.

Uploaded by

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

//xmlfile

<?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">

<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/firstNameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="First Name"/>
</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/lastNameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Last Name"/>
</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/emailEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Email"/>
</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/phoneNumberEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Phone Number"/>
</com.google.android.material.textfield.TextInputLayout>

<Button
android:id="@+id/submitButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:layout_gravity="center"
android:layout_marginTop="16dp"/>
</LinearLayout>

//main.java
package com.example.materialdesignforstudentregistration;

import android.os.Bundle;
import android.widget.Button;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.google.android.material.textfield.TextInputEditText;

public class MainActivity extends AppCompatActivity {

private TextInputEditText firstNameEditText;


private TextInputEditText lastNameEditText;
private TextInputEditText emailEditText;
private TextInputEditText phoneNumberEditText;
private Button submitButton;

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

firstNameEditText = findViewById(R.id.firstNameEditText);
lastNameEditText = findViewById(R.id.lastNameEditText);
emailEditText = findViewById(R.id.emailEditText);
phoneNumberEditText = findViewById(R.id.phoneNumberEditText);
submitButton = findViewById(R.id.submitButton);

submitButton.setOnClickListener(v -> {
String firstName = firstNameEditText.getText().toString();
String lastName = lastNameEditText.getText().toString();
String email = emailEditText.getText().toString();
String phoneNumber = phoneNumberEditText.getText().toString();

// Perform validation or other operations here

String message = "Registration Successful\n" +


"First Name: " + firstName + "\n" +
"Last Name: " + lastName + "\n" +
"Email: " + email + "\n" +
"Phone Number: " + phoneNumber;

Toast.makeText(this, message, Toast.LENGTH_LONG).show();


});
}
}

You might also like