CH 3
CH 3
W24
(c) Develop an android application to calculate age (Use Date Picker) using following GUI07
(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
W23
(c) List out various layouts available in Android. Explain any one with xml code file. 07
(c) Write code to display Toast Message “Welcome to Android” on click of a Button. 07
W22
(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
(c) What is Listview? Write a java class to add any 10 items within Listview. 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
S23
(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
(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
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
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)
Write both XML code and Android program to display a circular progress bar. (07,
W22)
🔶 3. Calculator Application
🔶 4. UI Components
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)
Describe Scroll View & List View? Explain with suitable Program. (04, S22)
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
🔶 12. Layouts
List out various layouts available in Android. Explain any one with XML code. (07,
W23)
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)
🔶 14. Spinner
How to use Spinner in Android App? Explain with an example. (04, W23)
How to use Spinner in Android App? Explain with an example. (04, S22)
🔶 15. Menus
What is the purpose of menu? How it can be used in Android? (04, S24)
🔶 16. RadioGroup
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)
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
🔶 23. ListView
What is ListView? Write a Java class to add any 10 items within ListView. (07, W22)
🔶 24. Checkbox
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"
Example:
android:screenOrientation="portrait"
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
If the user rotates the device, the screen automatically switches between portrait and
landscape.
Example:
android:sreenOrientation="sensor"
7. nosensor
Example:
android:screenOrientation="nosensor"
8. sensorPortrait
Example:
android:screenOrientation="sensorPortrait"
9. sensorLandscape
Example:
android:screenOrientation="sensorLandscape"
10. reversePortrait
Example:
android:screenOrientation="reversePortrait"
11. reverseLandscape
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
Example:
android:screenOrientation="locked
<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: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 {
Button btnShow;
TextView tvSelected;
@Override
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
if (cbMath.isChecked()) {
if (cbPhysics.isChecked()) {
if (cbChemistry.isChecked()) {
if (cbBiology.isChecked()) {
if (selected.equals("")) {
} else {
});
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
<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>
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;
@Override
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
rootLayout.setBackgroundColor(Color.RED);
});
greenButton.setOnClickListener(new View.OnClickListener() {
@Override
rootLayout.setBackgroundColor(Color.GREEN);
});
blueButton.setOnClickListener(new View.OnClickListener() {
@Override
rootLayout.setBackgroundColor(Color.BLUE);
}
});
✅ Summary
Let me know if you need the same implementation in Kotlin or with Jetpack Compose.
<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;
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.
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;
EditText etNumber;
Button btnCheck;
TextView tvResult;
@Override
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
if (!input.isEmpty()) {
if (num % 2 == 0) {
tvResult.setText("Even Number");
} else {
tvResult.setText("Odd Number");
} else {
}
});
<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: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
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;
Button btnSum;
TextView tvSum;
@Override
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
} else {
});
<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: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.
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
Phone Number
🔧 Step-by-Step Implementation
<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;
RadioGroup rgGender;
Spinner spDepartment;
Button btnRegister;
TextView tvResult;
@Override
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);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spDepartment.setAdapter(adapter);
btnRegister.setOnClickListener(new View.OnClickListener() {
@Override
return;
tvResult.setText(result);
});
}
✅ Output Example
When the user taps the "Register" button, the app shows:
Registration Details:
Email: [email protected]
Phone: 1234567890
Gender: Female
Kotlin version