0% found this document useful (0 votes)
7 views3 pages

Practical No 5.

The document contains an XML layout for an Android application that includes input fields for a user's name, age, and mobile number, along with a submit button. It also includes a Java class that initializes these views and sets a click listener on the submit button to display the entered data in a toast message. This setup is part of a student data collection application.

Uploaded by

Vaman Kulkarni
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)
7 views3 pages

Practical No 5.

The document contains an XML layout for an Android application that includes input fields for a user's name, age, and mobile number, along with a submit button. It also includes a Java class that initializes these views and sets a click listener on the submit button to display the entered data in a toast message. This setup is part of a student data collection application.

Uploaded by

Vaman Kulkarni
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/ 3

Practical No 5

<?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="20dp"

android:gravity="center">

<!-- Label and input for Name -->

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

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Name"

android:textSize="18sp"

android:paddingBottom="8dp"/>

<EditText android:id="@+id/nameInput"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:hint="Enter your name"

android:padding="10dp"/>

<!-- Label and input for Age -->

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

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Age"

android:textSize="18sp"

android:paddingTop="16dp"

android:paddingBottom="8dp"/>

<EditText android:id="@+id/ageInput"

android:layout_width="match_parent"
android:layout_height="wrap_content"

android:hint="Enter your age"

android:inputType="number"

android:padding="10dp"/>

<!-- Label and input for Mobile Number -->

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

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Mobile Number"

android:textSize="18sp"

android:paddingTop="16dp"

android:paddingBottom="8dp"/>

<EditText android:id="@+id/phoneInput"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:hint="Enter your mobile number"

android:inputType="phone"

android:padding="10dp"/>

<!-- Button to submit the data (optional) -->

<Button android:id="@+id/submitButton"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Submit"

android:layout_marginTop="20dp"/>

</LinearLayout>

---------------------------------------------------------------------------------

main.java

package com.example.studentdata;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
OUTPUT

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

private EditText nameInput, ageInput, phoneInput;

private Button submitButton;

@SuppressLint("MissingInflatedId")

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

// Initialize the views

nameInput = findViewById(R.id.nameInput);

ageInput = findViewById(R.id.ageInput);

phoneInput = findViewById(R.id.phoneInput);

submitButton = findViewById(R.id.submitButton);

// Set a click listener on the submit button

submitButton.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

// Get the text from EditText fields

String name = nameInput.getText().toString();

String age = ageInput.getText().toString();

String phone = phoneInput.getText().toString();

Toast.makeText(MainActivity.this, "Name: " + name + "\nAge: " + age + "\nPhone: " + phone,
Toast.LENGTH_LONG).show();

} });}

You might also like