0% found this document useful (0 votes)
22 views29 pages

CH 3

The document outlines various tasks and questions related to Android application development, including the use of Toast messages, circular progress bars, calculators, UI components, and event listeners. It also covers topics like orientation modes, layouts, and user input handling through different UI elements such as CheckBoxes and Buttons. Additionally, it provides examples of Android applications that demonstrate these concepts, along with XML layout and Java code snippets.

Uploaded by

Aesha Patel
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)
22 views29 pages

CH 3

The document outlines various tasks and questions related to Android application development, including the use of Toast messages, circular progress bars, calculators, UI components, and event listeners. It also covers topics like orientation modes, layouts, and user input handling through different UI elements such as CheckBoxes and Buttons. Additionally, it provides examples of Android applications that demonstrate these concepts, along with XML layout and Java code snippets.

Uploaded by

Aesha Patel
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/ 29

Ch3

W24

Demonstrate the use of Toast in Android. 04

Write and android application to display circular progress bar. 07 OR

(c) Develop a simple calculator using table layout. 07

Explain any four UI Components of Android application. 04

(c) Develop an android application to calculate age (Use Date Picker) using following GUI07

Q.3 (a) List different types of views? Explain Scroll view. 03

(c) Create an android application which displays three buttons on Main Activity named

RED, GREEN and BLUE. The background color of the activity should be changed

to appropriate color when user clicks on any of these buttons.07

W23

Discuss Fragments in Android? 03

Define Intent. Classify types of Intent with examples. 07

Write about ToggleButton in Android. 03

(b) What are the orientation modes of available in Android? 04

(c) List out various layouts available in Android. Explain any one with xml code file. 07

Q.3 (a) Discuss an OnClickListener event Listener in Android? 03

(b) How to use spinner in Android App? Explain with an example. 04

(c) Write code to display Toast Message “Welcome to Android” on click of a Button. 07

W22

Explain Date and Time picker with its methods. 04

(c) Write both XML code and android program to display a circular progress bar. 07 OR

(c) Develop the registration form that includes the following data in the GUI. 07

Explain Linear Layout with attributes. 04

(c) Develop a simple calculator using table layout. 07 OR Q.3

(a) Explain drawable resources in android 03

(b) Explain Grid Layout with attributes. 04

(c) What is Listview? Write a java class to add any 10 items within Listview. 07

Explain context menu and system menu. 03

Explain Option Menu. 03


S24

Demonstrate the concept of RadioGroup with an example. 03

(b) What is the purpose of menu? How it can be used in Android? 04

(c) Explain View and View Groups with an example. 07

Create an Android App in which student can select one or more subject from the group of
four subjects and prints the selected subject in Text View on button click. 07

Create Android App which will take a number from user using EditText and prints whether
the number is Even or Odd in TextView on button click. 07

Demonstrate the use of spinner in Android App. 07

S23

How menu can be used in Android App? 03

(b) Demonstrate the concept of RadioGroup with an example. 04

(c) Create Android App which will take two numbers from user using EditText and prints the
sum of both the numbers in TextView on button click. Ensure that users can enter numbers
only from the EditText. 07 OR

Q.3 (a) How AutoCompleteTextView can be used in Android App? 03

(b) Demonstrate the concept of ViewGroup with an example. 04

(c) Create an Android App in which employee can select one or more city from the group of
four cities and prints the selected cities in TextView on button click. 07

Q.4 (a) What is the significance of spinner in Android App? 03 (b) List out different layouts
available in Android and explain any one in detail. 04

S22

Explain Checkbox with example. 03

(b) How to use spinner in Android App? Explain with an example. 04

What is android layout? Explain different layout classes and working with layouts. 07

Make Application for student’s registration of basic details like Enrollment No, Name,
Branch, Address, Mobile Number, Email Id. 07

Explain android graphics interface. 04

Describe Scroll View & List View? Explain with suitable Program. 04

🔶 1. Toast
 Demonstrate the use of Toast in Android. (04, W24)

 Write code to display Toast Message “Welcome to Android” on click of a Button. (07,
W23)

🔶 2. Circular Progress Bar

 Write an Android application to display circular progress bar. (07, W24)

 Write both XML code and Android program to display a circular progress bar. (07,
W22)

🔶 3. Calculator Application

 Develop a simple calculator using TableLayout. (07, W24)

 Develop a simple calculator using TableLayout. (07, W22)

🔶 4. UI Components

 Explain any four UI Components of Android application. (04, W24)

🔶 5. Date Picker / Age Calculator

 Develop an Android application to calculate age (Use Date Picker) using following
GUI. (07, W24)

 Explain Date and Time picker with its methods. (04, W22)

🔶 6. Views and ScrollView

 List different types of views? Explain ScrollView. (03, W24)

 Describe Scroll View & List View? Explain with suitable Program. (04, S22)

🔶 7. Button Color Change App

 Create an Android application which displays three buttons on Main Activity named
RED, GREEN and BLUE. The background color of the activity should be changed to
appropriate color when user clicks on any of these buttons. (07, W24)

🔶 10. ToggleButton

 Write about ToggleButton in Android. (03, W23)

🔶 11. Orientation Modes


 What are the orientation modes available in Android? (04, W23)

🔶 12. Layouts

 List out various layouts available in Android. Explain any one with XML code. (07,
W23)

 Explain Linear Layout with attributes. (04, W22)

 Explain Grid Layout with attributes. (04, W22)

 What is android layout? Explain different layout classes and working with layouts.
(07, S22)

 List out different layouts available in Android and explain any one in detail. (04, S23)

🔶 13. Event Listener

 Discuss an OnClickListener event Listener in Android. (03, W23)

🔶 14. Spinner

 How to use Spinner in Android App? Explain with an example. (04, W23)

 Demonstrate the use of Spinner in Android App. (07, S24)

 How to use Spinner in Android App? Explain with an example. (04, S22)

 What is the significance of spinner in Android App? (03, S23)

🔶 15. Menus

 Explain context menu and system menu. (03, W22)

 Explain Option Menu. (03, W22)

 How menu can be used in Android App? (03, S23)

 What is the purpose of menu? How it can be used in Android? (04, S24)

🔶 16. RadioGroup

 Demonstrate the concept of RadioGroup with an example. (03, S24)

 Demonstrate the concept of RadioGroup with an example. (04, S23)

🔶 17. View and ViewGroup

 Explain View and View Groups with an example. (07, S24)

 Demonstrate the concept of ViewGroup with an example. (04, S23)


🔶 18. Selection-Based Apps

 Create Android App in which student can select one or more subjects and display
selected subjects. (07, S24)

 Create Android App in which employee can select one or more cities and display
selected cities. (07, S23)

🔶 19. Number Check / Calculation Apps

 Create Android App which takes a number and displays even or odd. (07, S24)

 Create Android App which takes two numbers and displays the sum. (07, S23)

🔶 20. AutoCompleteTextView

 How AutoCompleteTextView can be used in Android App? (03, S23)

🔶 21. Registration Form

 Develop the registration form with GUI elements. (07, W22)

 Make Application for student’s registration of basic details. (07, S22)

🔶 22. Drawable Resources

 Explain drawable resources in Android. (03, W22)

🔶 23. ListView

 What is ListView? Write a Java class to add any 10 items within ListView. (07, W22)

🔶 24. Checkbox

 Explain Checkbox with example. (03, S22)

🔶 25. Graphics Interface

 Explain Android graphics interface. (04, S22)

In Android, the screen orientation determines how an activity appears on the device's
display. Android provides several orientation modes, which can be set in the
AndroidManifest.xml file using the android:screenOrientation attribute or dynamically in
Java/Kotlin.
Types of Orientation Modes in Android

1. unspecified (default)The system chooses the best orientation based on the device's
settings and physical rotation.

Example:

android:screenOrientation="unspecified"

2. portraitThe activity is always displayed in portrait mode (vertical).

Example:

android:screenOrientation="portrait"

3. landscapeThe activity is always displayed in landscape mode (horizontal).

Example:

android:screenOrientation="landscape"

4. user

The orientation follows the user’s preference set in the device settings.

Example:

android:screenOrientation="user"

5. behind

The activity adopts the orientation of the activity behind it in the activity stack.

Example:

android:screenOrientation="behind"

6. sensor

The screen orientation is determined by the device's accelerometer.

If the user rotates the device, the screen automatically switches between portrait and
landscape.

Example:

android:sreenOrientation="sensor"

7. nosensor

The activity ignores sensor-based orientation changes.

Example:

android:screenOrientation="nosensor"

8. sensorPortrait

Uses the sensor to determine portrait orientation (normal or reverse).

Example:

android:screenOrientation="sensorPortrait"
9. sensorLandscape

Uses the sensor to determine landscape orientation (normal or reverse).

Example:

android:screenOrientation="sensorLandscape"

10. reversePortrait

Locks the activity in an upside-down portrait mode.

Example:

android:screenOrientation="reversePortrait"

11. reverseLandscape

Locks the activity in an upside-down landscape mode.

Example:

android:screenOrientation="reverseLandscape"

12. fullSensor

Allows all four orientations (portrait, reverse portrait, landscape, reverse landscape) based
on the device rotation.

Example:

android:screenOrientation="fullSensor"

13. fullUser

Similar to fullSensor, but it respects the user's preferences for rotation settings.

Example:

android:screenOrientation="fullUser"

14. locked

Locks the activity in its current orientation, preventing changes.

Example:

android:screenOrientation="locked

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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:id="@+id/rootLayout"

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

android:orientation="vertical"

android:padding="20dp"

android:gravity="center"

android:background="#F5F5F5">

<TextView

android:id="@+id/title"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Select Subjects"

android:textSize="24sp"

android:textStyle="bold"

android:layout_marginBottom="20dp"/>

<CheckBox

android:id="@+id/cbMath"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Mathematics"/>

<CheckBox

android:id="@+id/cbPhysics"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Physics"/>

<CheckBox

android:id="@+id/cbChemistry"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Chemistry"/>
<CheckBox

android:id="@+id/cbBiology"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Biology"/>

<Button

android:id="@+id/showBtn"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Show Selected Subjects"

android:layout_marginTop="20dp"/>

<TextView

android:id="@+id/resultText"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text=""

android:textSize="18sp"

android:textColor="#333333"

android:layout_marginTop="20dp"/>

</LinearLayout>

package com.example.selectsubjects;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.CheckBox;

import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {

CheckBox cbMath, cbPhysics, cbChemistry, cbBiology;

Button btnShow;

TextView tvSelected;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

cbMath = findViewById(R.id.cbMath);

cbPhysics = findViewById(R.id.cbPhysics);

cbChemistry = findViewById(R.id.cbChemistry);

cbBiology = findViewById(R.id.cbBiology);

btnShow = findViewById(R.id.btnShow);

tvSelected = findViewById(R.id.tvSelected);

btnShow.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

String selected = "";

if (cbMath.isChecked()) {

selected = selected + "Mathematics\n";

if (cbPhysics.isChecked()) {

selected = selected + "Physics\n";

if (cbChemistry.isChecked()) {

selected = selected + "Chemistry\n";


}

if (cbBiology.isChecked()) {

selected = selected + "Biology\n";

if (selected.equals("")) {

tvSelected.setText("No subject selected.");

} else {

tvSelected.setText("Selected Subjects:\n" + selected);

});

Here’s how you can create a simple Android application that changes the background color
of the MainActivity when the user clicks on RED, GREEN, or BLUE buttons.

✅ Step-by-Step Implementation

1. XML Layout (activity_main.xml)

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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:id="@+id/rootLayout"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

android:gravity="center"

android:padding="16dp"

android:background="#FFFFFF">

<Button

android:id="@+id/redButton"
android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="RED"

android:layout_margin="10dp" />

<Button

android:id="@+id/greenButton"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="GREEN"

android:layout_margin="10dp" />

<Button

android:id="@+id/blueButton"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="BLUE"

android:layout_margin="10dp" />

</LinearLayout>

2. Java Code (MainActivity.java)

package com.example.colorchanger;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Color;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.LinearLayout;

public class MainActivity extends AppCompatActivity {


LinearLayout rootLayout;

Button redButton, greenButton, blueButton;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

rootLayout = findViewById(R.id.rootLayout);

redButton = findViewById(R.id.redButton);

greenButton = findViewById(R.id.greenButton);

blueButton = findViewById(R.id.blueButton);

redButton.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

rootLayout.setBackgroundColor(Color.RED);

});

greenButton.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

rootLayout.setBackgroundColor(Color.GREEN);

});

blueButton.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

rootLayout.setBackgroundColor(Color.BLUE);

}
});

✅ Summary

 You have 3 buttons: RED, GREEN, and BLUE.

 On click, the LinearLayout background changes to the corresponding color.

 Simple setBackgroundColor() is used with predefined Color constants.

Let me know if you need the same implementation in Kotlin or with Jetpack Compose.

Simple Calculator using Table Layout


XML Code
<?xml version="1.0" encoding="utf-8"?>
<TableLayout 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="#6AF6E9"
android:shrinkColumns="=1"
tools:context=".MainActivity" >

<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="30sp"
android:layout_marginTop="40sp"
android:layout_marginRight="30sp"
android:background="#3F51B5">

<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:paddingLeft="70sp"
android:text="Simple Calculator"
android:textColor="#FF5722"
android:textSize="24sp"
android:textStyle="bold" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="60sp"
android:layout_marginTop="40sp"
android:layout_marginRight="60sp">

<EditText
android:id="@+id/edit1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="number" />
</TableRow>

<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="60sp"
android:layout_marginTop="50sp"
android:layout_marginRight="60sp">

<EditText
android:id="@+id/edit2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="number" />
</TableRow>

<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="40sp"
android:layout_marginTop="40sp"
android:layout_marginRight="40sp">

<Button
android:id="@+id/addbtn"
android:layout_width="161dp"
android:layout_height="match_parent"
android:layout_marginRight="70sp"
android:layout_weight="1"
android:text="ADD" />

<Button
android:id="@+id/subbtn"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:foregroundGravity="right"
android:text="SUB" />

</TableRow>

<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="40sp"
android:layout_marginTop="40sp"
android:layout_marginRight="40sp">

<Button
android:id="@+id/mulbtn"
android:layout_width="106dp"
android:layout_height="wrap_content"
android:layout_marginRight="70sp"
android:layout_weight="1"
android:text="MUL" />

<Button
android:id="@+id/divbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="DIV" />

</TableRow>

<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="50sp"
android:layout_marginTop="40sp"
android:layout_marginRight="50sp">

<EditText
android:id="@+id/edit3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:ems="10"
android:inputType="number" />
</TableRow>
</TableLayout>

JAVA Code
package com.example.s_calulator;

import androidx.appcompat.app.AppCompatActivity;

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

public class MainActivity extends AppCompatActivity {


EditText edit1,edit2,edit3;
Button addbtn,subbtn,mulbtn,divbtn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edit1=(EditText) findViewById(R.id.edit1);
edit2=(EditText) findViewById(R.id.edit2);
edit3=(EditText) findViewById(R.id.edit3);
addbtn=(Button)findViewById(R.id.addbtn);
subbtn=(Button)findViewById(R.id.subbtn);
mulbtn=(Button)findViewById(R.id.mulbtn);
divbtn=(Button)findViewById(R.id.divbtn);

addbtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int n1=Integer.parseInt(edit1.getText().toString());
int n2=Integer.parseInt(edit2.getText().toString());
int ans=n1+n2;
edit3.setText(Integer.toString(ans));

}
});
subbtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int n1=Integer.parseInt(edit1.getText().toString());
int n2=Integer.parseInt(edit2.getText().toString());
int ans=n1-n2;
edit3.setText(Integer.toString(ans));

}
});
mulbtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int n1=Integer.parseInt(edit1.getText().toString());
int n2=Integer.parseInt(edit2.getText().toString());
int ans=n1*n2;
edit3.setText(Integer.toString(ans));

}
});
divbtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int n1=Integer.parseInt(edit1.getText().toString());
int n2=Integer.parseInt(edit2.getText().toString());
int ans=n1/n2;
edit3.setText(""+ans);

}
});

Here are two simple Android apps written in Java using EditText for user input and a Button
to trigger the action. Each app uses a TextView to display the result.

✅ App 1: Even or Odd Checker

Java Code – MainActivity.java

package com.example.evenoddchecker;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

EditText etNumber;

Button btnCheck;

TextView tvResult;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

etNumber = findViewById(R.id.etNumber);

btnCheck = findViewById(R.id.btnCheck);

tvResult = findViewById(R.id.tvResult);

btnCheck.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

String input = etNumber.getText().toString();

if (!input.isEmpty()) {

int num = Integer.parseInt(input);

if (num % 2 == 0) {

tvResult.setText("Even Number");

} else {

tvResult.setText("Odd Number");

} else {

tvResult.setText("Please enter a number");

}
});

XML Layout – activity_main.xml

<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="24dp">

<EditText

android:id="@+id/etNumber"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:hint="Enter a number"

android:inputType="number" />

<Button

android:id="@+id/btnCheck"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Check Even or Odd"

android:layout_marginTop="16dp" />

<TextView

android:id="@+id/tvResult"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text=""

android:textSize="18sp"

android:layout_marginTop="16dp"/>

</LinearLayout>
✅ App 2: Sum of Two Numbers

Java Code – MainActivity.java

package com.example.sumtwonumbers;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

EditText etNum1, etNum2;

Button btnSum;

TextView tvSum;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

etNum1 = findViewById(R.id.etNum1);

etNum2 = findViewById(R.id.etNum2);

btnSum = findViewById(R.id.btnSum);

tvSum = findViewById(R.id.tvSum);

btnSum.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

String str1 = etNum1.getText().toString();


String str2 = etNum2.getText().toString();

if (!str1.isEmpty() && !str2.isEmpty()) {

int num1 = Integer.parseInt(str1);

int num2 = Integer.parseInt(str2);

int sum = num1 + num2;

tvSum.setText("Sum: " + sum);

} else {

tvSum.setText("Enter both numbers");

});

XML Layout – activity_main.xml

<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="24dp">

<EditText

android:id="@+id/etNum1"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:hint="Enter first number"

android:inputType="number" />

<EditText

android:id="@+id/etNum2"

android:layout_width="match_parent"

android:layout_height="wrap_content"
android:hint="Enter second number"

android:inputType="number"

android:layout_marginTop="8dp" />

<Button

android:id="@+id/btnSum"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Calculate Sum"

android:layout_marginTop="16dp" />

<TextView

android:id="@+id/tvSum"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text=""

android:textSize="18sp"

android:layout_marginTop="16dp"/>

</LinearLayout>

Let me know if you'd like Kotlin versions or to combine both features into a single app.

Here’s a simple Android app that fulfills both of your requirements:

✅ App Title: Student Registration Form

This app allows students to input their basic details using GUI elements like EditText,
RadioButton, Spinner, and Button. When the user taps "Register", their input is shown on
screen.

🧠 Data Collected

 Name

 Email

 Phone Number

 Gender (Radio Buttons)


 Department (Spinner)

 Result Display (TextView)

🔧 Step-by-Step Implementation

📄 activity_main.xml (GUI Layout)

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent">

<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="vertical"

android:padding="24dp">

<EditText

android:id="@+id/etName"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:hint="Full Name"

android:inputType="textPersonName" />

<EditText

android:id="@+id/etEmail"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:hint="Email"

android:inputType="textEmailAddress"

android:layout_marginTop="8dp"/>

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

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:hint="Phone Number"

android:inputType="phone"

android:layout_marginTop="8dp"/>

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Gender:"

android:layout_marginTop="12dp" />

<RadioGroup

android:id="@+id/rgGender"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:orientation="horizontal">

<RadioButton

android:id="@+id/rbMale"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Male" />

<RadioButton

android:id="@+id/rbFemale"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Female" />

</RadioGroup>
<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Department:"

android:layout_marginTop="12dp" />

<Spinner

android:id="@+id/spDepartment"

android:layout_width="match_parent"

android:layout_height="wrap_content" />

<Button

android:id="@+id/btnRegister"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Register"

android:layout_marginTop="16dp" />

<TextView

android:id="@+id/tvResult"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text=""

android:textSize="16sp"

android:layout_marginTop="16dp"/>

</LinearLayout>

</ScrollView>

📘 MainActivity.java (Logic)

package com.example.registrationapp;

import android.os.Bundle;
import android.view.View;

import android.widget.*;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

EditText etName, etEmail, etPhone;

RadioGroup rgGender;

Spinner spDepartment;

Button btnRegister;

TextView tvResult;

String[] departments = {"Computer Science", "Mechanical", "Electrical", "Civil", "IT"};

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

etName = findViewById(R.id.etName);

etEmail = findViewById(R.id.etEmail);

etPhone = findViewById(R.id.etPhone);

rgGender = findViewById(R.id.rgGender);

spDepartment = findViewById(R.id.spDepartment);

btnRegister = findViewById(R.id.btnRegister);

tvResult = findViewById(R.id.tvResult);

// Set spinner data

ArrayAdapter<String> adapter = new ArrayAdapter<>(this,


android.R.layout.simple_spinner_item, departments);

adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

spDepartment.setAdapter(adapter);
btnRegister.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

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

String email = etEmail.getText().toString();

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

int selectedGenderId = rgGender.getCheckedRadioButtonId();

if (name.isEmpty() || email.isEmpty() || phone.isEmpty() || selectedGenderId == -


1) {

tvResult.setText("Please fill all fields.");

return;

RadioButton selectedGender = findViewById(selectedGenderId);

String gender = selectedGender.getText().toString();

String dept = spDepartment.getSelectedItem().toString();

String result = "Registration Details:\n"

+ "Name: " + name + "\n"

+ "Email: " + email + "\n"

+ "Phone: " + phone + "\n"

+ "Gender: " + gender + "\n"

+ "Department: " + dept;

tvResult.setText(result);

});

}
✅ Output Example

When the user taps the "Register" button, the app shows:

Registration Details:

Name: Jane Doe

Email: [email protected]

Phone: 1234567890

Gender: Female

Department: Computer Science

Let me know if you'd like:

 Kotlin version

 Data saved to local storage or database

 Separate confirmation screen after registration

You might also like