0% found this document useful (0 votes)
18 views39 pages

Android Development Lab Manual 2024

The document is a lab manual for Android Development using Java/Kotlin at SAGE University Indore, detailing experiments and their objectives for the academic year 2024-25. It includes a list of experiments, such as installing Android Studio, creating a Hello World application, and developing user registration applications with various input fields. Each experiment outlines materials, safety precautions, procedures, results, and conclusions to guide students in their practical learning.
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)
18 views39 pages

Android Development Lab Manual 2024

The document is a lab manual for Android Development using Java/Kotlin at SAGE University Indore, detailing experiments and their objectives for the academic year 2024-25. It includes a list of experiments, such as installing Android Studio, creating a Hello World application, and developing user registration applications with various input fields. Each experiment outlines materials, safety precautions, procedures, results, and conclusions to guide students in their practical learning.
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

SAGE University Indore

LAB MANUAL

Subject Code: - Android Development Using


java/Kotlin Subject Name: - ACTDCAND001T
Year: III, SEMESTER: V
Session: -2024-25

Submitted to: Submitted by:

Prof. Anshita kesharwani Name: -…….………

Enrollment no.: -…….


INDEX
Experi Date of Date of Signature
ment Title of Experiment Experiment submission
no.

1 Installation of Android Studio


06-08-2025

2 Development of Hello World Application


13-08-2025
Create an application that takes the
name from a text box and shows hello
3
message along with the name entered in
text box, when the user clicks the OK 20-08-2025
button.

Create a screen that has input boxes for


User Name, Password, Address and
Gender (radio buttons for male and
4 female), Age (numeric), Date of Birth
(Date Picker), State (Spinner) and a Submit
button.
On clicking the submit button, print all the
data below the Submit Button (use any 03-09-2025
layout).
Design an android application to create
page using Intent and one Button and pass
5
the values from one Activity to second
Activity. 10-09-2025
Design an android application to send SMS
6
using Intent. 17-09-2025
Create an android application using
7
Fragments. 24-09-2025
Design an android application using Radio
8
buttons. 08-10-2025

9
Design an android application for Menu. 15-10-2025
Create a user registration application that
10
stores the user details in a database table. 29-10-2025
Experiment Number 01
Experiment Title Installation of Android Studio

Objective To install and configure Android Studio IDE for Android application
development.

Android Studio is the official IDE for Android development, based on


Introduction IntelliJ IDEA. It provides tools for building apps, designing layouts, and
testing on emulators.

• Computer/Laptop (8GB RAM recommended)

• Windows/Linux/macOS OS
Materials
• Android Studio installer

• JDK (Java Development Kit)

• Ensure sufficient disk space and RAM.


Safety Precautions
• Use stable internet connection.

• Avoid forcefully closing installation.


• Download Android Studio from official website.
• Run installer and follow setup wizard.
Procedure • Install SDK components and emulator.
• Configure JDK path if required.
• Launch Android Studio and create a sample project.
Android Studio installed successfully with SDK and emulator
Results running.

Analysis/ Correct installation ensures a stable environment for Android app


development. Issues like missing JDK or low memory may cause errors.
Discussion

Conclusion
Android Studio setup is complete and system is ready for development.
Experiment Number 02
Experiment Title Development of Hello World Application

Objective To create a simple Android app that displays "Hello World".

Introduction The Hello World program is the basic test for any programming
environment.

• Android Studio
Materials
• Emulator/Android Device

• Ensure Android Studio is properly installed.


Safety Precautions
• Do not disconnect device while installing APK.

1. Open Android Studio → Create New Project → Empty Activity.


2. Name project "HelloWorldApp".
Procedure 3. Edit activity_main.xml to include a TextView.
4. In [Link], set layout.
5. Run app on emulator/device.

Results The app displayed "Hello World" on screen.

Analysis /
This verified that IDE setup and build system are correct.
Discussion

Conclusion The Hello World application was created successfully.


Experiment
03
Number
Experiment Create an application that takes the name from a text box and shows hello message along
Title with the name entered in text box, when the user clicks the OK button.

Step 1: activity_main.xml

This file defines the UI layout — one EditText for input, one Button, and one TextView for
Implementation output.

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


<LinearLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="20dp"
android:gravity="center">

<EditText
android:id="@+id/etName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter your name"
android:textSize="18sp"
android:inputType="textPersonName" />

<Button
android:id="@+id/btnOk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="OK"
android:layout_marginTop="20dp" />

<TextView
android:id="@+id/tvResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:textStyle="bold"
android:layout_marginTop="20dp"
android:textColor="@android:color/black" />

</LinearLayout>
Step 2: [Link]

This is the main activity where logic is written.

package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity

{ EditText etName;
Button btnOk;
TextView tvResult;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

etName = findViewById([Link]);
btnOk = findViewById([Link]);
tvResult = findViewById([Link]);

[Link](new [Link]() {
@Override
public void onClick(View view) {
String name = [Link]().toString().trim();

if (![Link]())
{ [Link]("Hello " + name +
"!");
} else {
[Link]("Please enter your name.");
}
}
});
}
}
OUTPUT

[Enter your name: ]


[ OK ]

Hello Ankita!
Experiment 04
Number
Experiment Create a screen that has input boxes for User Name, Password, Address and Gender
Title (radio buttons for male and female), Age (numeric), Date of Birth (Date Picker), State
(Spinner) and a Submit button.
On clicking the submit button, print all the data below the Submit Button (use any
layout).

Implementation Step 1: activity_main.xml

This layout contains all input fields and a TextView to show the output below the Submit
button.

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


<ScrollView xmlns:android="[Link]
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="20dp">

<!-- User Name -->


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

<!-- Password -->


<EditText
android:id="@+id/etPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Password"
android:inputType="textPassword"
android:layout_marginTop="10dp" />

<!-- Address -->


<EditText
android:id="@+id/etAddress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Address"
android:inputType="textPostalAddress"
android:layout_marginTop="10dp" />

<!-- Gender -->


<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Gender:"
android:textSize="16sp"
android:layout_marginTop="10dp" />

<RadioGroup
android:id="@+id/rgGender"
android:layout_width="match_parent"
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>

<!-- Age -->


<EditText
android:id="@+id/etAge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Age"
android:inputType="number"
android:layout_marginTop="10dp" />

<!-- Date of Birth -->


<EditText
android:id="@+id/etDob"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Select Date of Birth"
android:focusable="false"
android:layout_marginTop="10dp" />

<!-- State Spinner -->


<Spinner
android:id="@+id/spinnerState"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" />

<!-- Submit Button -->


<Button
android:id="@+id/btnSubmit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:layout_marginTop="20dp" />
<!-- Output Display -->
<TextView
android:id="@+id/tvResult"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textSize="16sp"
android:layout_marginTop="20dp"
android:textColor="@android:color/black" />
</LinearLayout>
</ScrollView>
Step 2: [Link]
Handles the logic: getting user inputs, showing DatePicker, and displaying data.

package [Link];
import [Link];
import [Link];
import [Link];
import [Link].*;
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {

EditText etName, etPassword, etAddress, etAge, etDob;


RadioGroup rgGender;
Spinner spinnerState;
Button btnSubmit;
TextView tvResult;
String gender = "";

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

etName = findViewById([Link]);
etPassword = findViewById([Link]);
etAddress = findViewById([Link]);
etAge = findViewById([Link]);
etDob = findViewById([Link]);
rgGender = findViewById([Link]);
spinnerState = findViewById([Link]);
btnSubmit = findViewById([Link]);
tvResult = findViewById([Link]);

// Spinner Data
String[] states = {"Select State", "Madhya Pradesh", "Uttar Pradesh", "Maharashtra",
"Gujarat", "Rajasthan"};
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
[Link].simple_spinner_item, states);
[Link]([Link].simple_spinner_dropdown_item);
[Link](adapter);

// DatePicker
[Link](new [Link]() {
@Override
public void onClick(View v) {
final Calendar calendar = [Link]();
int year = [Link]([Link]);
int month = [Link]([Link]);
int day = [Link](Calendar.DAY_OF_MONTH);

DatePickerDialog datePickerDialog = new DatePickerDialog([Link],


(view, year1, month1, dayOfMonth) -> {
[Link](dayOfMonth + "/" + (month1 + 1) + "/" + year1);
}, year, month, day);
[Link]();
}
});

// Submit Button Click


[Link](new [Link]() {
@Override
public void onClick(View v) {
int selectedId = [Link]();
RadioButton selectedRadioButton = findViewById(selectedId);
if (selectedRadioButton != null)
gender = [Link]().toString();

String name = [Link]().toString();


String password = [Link]().toString();
String address = [Link]().toString();
String age = [Link]().toString();
String dob = [Link]().toString();
String state = [Link]().toString();

if ([Link]() || [Link]() || [Link]() || [Link]() ||


[Link]() || [Link]("Select State") || [Link]()) {
[Link]([Link], "Please fill all details",
Toast.LENGTH_SHORT).show();
} else {
String result = "User Details:\n\n"
+ "Name: " + name + "\n"
+ "Password: " + password + "\n"
+ "Address: " + address + "\n"
+ "Gender: " + gender + "\n"
+ "Age: " + age + "\n"
+ "DOB: " + dob + "\n"
+ "State: " + state;

[Link](result);
}
}
});
}
}

OUTPUT Input Screen:

User Name: [Ankita]


Password: [12345]
Address: [Bhopal, MP]
Gender: (•) Female ( ) Male
Age: [22]
DOB: [10/11/2003]
State: [Madhya Pradesh]
[ Submit ]

Output Display Below:

User Details:

Name: Ankita
Password: 12345
Address: Bhopal, MP
Gender: Female
Age: 22
DOB: 10/11/2003
State: Madhya Pradesh
Experiment 05
Number
Experiment Design an android application to create page using Intent and one Button and pass the
Title values from one Activity to second Activity.
Android app using Explicit Intent.
• MainActivity – Has a button and a text field to send data.

• SecondActivity – Receives and displays the data.

Step 1: Create a New Project


1. Open Android Studio.
2. Select New Project → Empty Activity → Next.
3. Name it: myapp
4. Language: Java
5. Finish

Step 2: Design activity_main.xml in res folder/layout


subfolder
<LinearLayout xmlns:android="[Link]

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

android:gravity="center"

android:padding="20dp">

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Enter Your Name:"

android:textSize="18sp"

android:layout_marginBottom="10dp"/>

<EditText

android:id="@+id/editTextName"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:hint="Type here"
android:padding="10dp"

android:background="@android:drawable/edit_text"/>

<Button

android:id="@+id/buttonSend"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Go to Next Activity"

android:layout_marginTop="20dp"/>

</LinearLayout>

Also create design using drag and drop option


Step 3: Create Second Activity Layout
activity_second.xml
CREATE SECOND ACTIVITY CLICK IN RIGHT OF [Link] THEN CLICK ON NEW THEN
SELECT Empty view activity automatically and then second activity create using SecondActivity name
<!-- res/layout/activity_second.xml -->

<LinearLayout xmlns:android="[Link]

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

android:gravity="center"

android:padding="20dp">

<TextView

android:id="@+id/textViewResult"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Result will appear here"

android:textSize="20sp"/>

</LinearLayout>

Save the file second activity design


Step 4: Code for [Link]
package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {

EditText editTextName;
Button buttonSend;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

editTextName = findViewById([Link]);
buttonSend = findViewById([Link]);

[Link](new [Link]() {
@Override
public void onClick(View v) {
String name = [Link]().toString();

// Explicit Intent to open SecondActivity


Intent intent = new Intent([Link], [Link]);

// Passing data to SecondActivity


[Link]("userName", name);

startActivity(intent);
}
});
}
}

save clrt+s
Step 5: Code for [Link]
package [Link];

import [Link];
import [Link];
import [Link];

public class SecondActivity extends AppCompatActivity

{ TextView textViewResult;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_second);

textViewResult = findViewById([Link]);

// Get the data from Intent


String name = getIntent().getStringExtra("userName");

// Display the data


[Link]("Hello, " + name + "!");
}
}
then save the file and then virtual device connect and the run
Experiment 06
Number
Experiment
Title Design an android application to send SMS using Intent.
Step 1: activity_main.xml
Implementation
This layout contains two text boxes (for phone number and message) and a Send button.

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


<LinearLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="20dp"
android:gravity="center">

<EditText
android:id="@+id/etPhone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter phone number"
android:inputType="phone"
android:textSize="18sp" />

<EditText
android:id="@+id/etMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter message"
android:inputType="textMultiLine"
android:lines="3"
android:layout_marginTop="15dp"
android:textSize="18sp" />

<Button
android:id="@+id/btnSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send SMS"
android:layout_marginTop="20dp" />

</LinearLayout>
Step 2: [Link]

package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import
[Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity

{ EditText etPhone, etMessage;


Button btnSend;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

etPhone = findViewById([Link]);
etMessage = findViewById([Link]);
btnSend = findViewById([Link]);

[Link](new [Link]() {
@Override
public void onClick(View view) {
String phone = [Link]().toString().trim();
String message = [Link]().toString().trim();

if ([Link]() || [Link]())
{ [Link]([Link], "Please enter phone and message",
Toast.LENGTH_SHORT).show();
} else {
// Create the SMS Intent
Intent intent = new Intent(Intent.ACTION_VIEW);
[Link]([Link]("[Link] + phone));
[Link]("sms_body", message);

// Start the SMS app


startActivity(intent);
}
}
});
}
}
OUTPUT

Enter phone number: 9876543210


Enter message: Hello, how are you?
[ Send SMS ]

To: 9876543210
Message: Hello, how are you?
Experiment 07
Number
Experiment
Title Create an android application using Fragments.
Implementation Step 1: activity_main.xml

This is the main layout that contains two buttons and a FrameLayout where
fragments will be loaded.

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


<LinearLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="20dp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">

<Button
android:id="@+id/btnFragmentA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Fragment A" />

<Button
android:id="@+id/btnFragmentB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Fragment B"
android:layout_marginStart="20dp" />
</LinearLayout>

<FrameLayout
android:id="@+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="30dp" />
</LinearLayout>
Step 2: [Link]

package [Link];

import [Link];
import [Link];
import [Link];
import [Link];

import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity

{ Button btnFragmentA, btnFragmentB;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

btnFragmentA = findViewById([Link]);
btnFragmentB = findViewById([Link]);

// Load Fragment A by default


loadFragment(new FragmentA());

[Link](new [Link]() {
@Override
public void onClick(View v)
{ loadFragment(new
FragmentA());
}
});

[Link](new [Link]() {
@Override
public void onClick(View v)
{ loadFragment(new
FragmentB());
}
});
}

private void loadFragment(Fragment fragment)


{ FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = [Link]();
[Link]([Link], fragment);
[Link]();
}
}
Step 3: Create [Link]

package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class FragmentA extends Fragment {

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
TextView textView = new TextView(getActivity());
[Link]("Welcome to Fragment A");
[Link](24);
[Link](50, 50, 50, 50);
return textView;
}
}

Step 4: Create [Link]

package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class FragmentB extends Fragment {

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
TextView textView = new TextView(getActivity());
[Link]("Welcome to Fragment B");
[Link](24);
[Link](50, 50, 50, 50);
return textView;
}
}
Step 5: [Link]

<manifest xmlns:android="[Link]
package="[Link]">

<application
android:allowBackup="true"
android:label="Fragment Example"
android:supportsRtl="true"
android:theme="@style/[Link]">

<activity android:name=".MainActivity">
<intent-filter>
<action android:name="[Link]"/>
<category android:name="[Link]"/>
</intent-filter>
</activity>

</application>
</manifest>

OUTPUT
[ Show Fragment A ] [ Show Fragment B ]

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

Welcome to Fragment A

When you tap “Show Fragment A”, it displays:

Welcome to Fragment A

When you tap “Show Fragment B”, it changes to:

Welcome to Fragment B

Experiment 08
Number
Experiment
Title Design an android application using Radio buttons.
Step 1: activity_main.xml
Implementation
This file defines the UI layout — a RadioGroup with three RadioButtons, a Button, and a
TextView for output.

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


<LinearLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="20dp"
android:gravity="center">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select your Gender:"
android:textSize="20sp"
android:layout_marginBottom="20dp" />

<RadioGroup
android:id="@+id/radioGroupGender"
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<RadioButton
android:id="@+id/radioMale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male" />

<RadioButton
android:id="@+id/radioFemale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female" />

<RadioButton
android:id="@+id/radioOther"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Other" />
</RadioGroup>

<Button
android:id="@+id/btnSubmit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:layout_marginTop="20dp" />

<TextView
android:id="@+id/tvResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:layout_marginTop="30dp"
android:textStyle="bold" />
</LinearLayout>

Step 2: [Link]

package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity

{ RadioGroup radioGroupGender;
Button btnSubmit;
TextView tvResult;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

radioGroupGender = findViewById([Link]);
btnSubmit = findViewById([Link]);
tvResult = findViewById([Link]);

[Link](new [Link]() {
@Override
public void onClick(View v) {

int selectedId = [Link]();

if (selectedId == -1) {
[Link]([Link], "Please select your gender",
Toast.LENGTH_SHORT).show();
} else {
RadioButton selectedRadioButton = findViewById(selectedId);
String selectedGender = [Link]().toString();
[Link]("Selected Gender: " + selectedGender);
}
}
});
}
}
Step 3: [Link]

<manifest xmlns:android="[Link]
package="[Link]">

<application
android:allowBackup="true"
android:label="Radio Button App"
android:supportsRtl="true"
android:theme="@style/[Link]">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="[Link]" />
<category android:name="[Link]" />
</intent-filter>
</activity>
</application>

</manifest>

Select your Gender:


Output
(o) Male

( ) Female

( ) Other

[ Submit ]

On clicking Submit:

If you select Male and click Submit, the app displays:

Selected Gender: Male

If you don’t select anything, it shows a Toast message:

Please select your gender

Experiment 09
Number
Experiment
Title Design an android application for Menu.
Implementation Step 1: activity_main.xml

This layout just contains a simple TextView to display the selected menu item.

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


<LinearLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:padding="20dp">

<TextView
android:id="@+id/tvMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select an option from the menu"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="@android:color/black" />
</LinearLayout>

Step 2: Create Menu Resource — res/menu/main_menu.xml

This XML file defines the menu items.

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


<menu xmlns:android="[Link]
<item
android:id="@+id/menu_home"
android:title="Home"
android:icon="@android:drawable/ic_menu_view"
android:showAsAction="ifRoom" />
<item
android:id="@+id/menu_settings"
android:title="Settings"
android:icon="@android:drawable/ic_menu_manage"
android:showAsAction="ifRoom" />
<item
android:id="@+id/menu_about"
android:title="About"
android:icon="@android:drawable/ic_menu_info_details"
android:showAsAction="ifRoom" />
</menu>
Step 3: [Link]

This Java code creates and handles the menu actions.

package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity

{ TextView tvMessage;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

tvMessage = findViewById([Link]);
}

// Create the menu


@Override
public boolean onCreateOptionsMenu(Menu menu)
{ MenuInflater inflater = getMenuInflater();
[Link]([Link].main_menu, menu);
return true;
}

// Handle menu item clicks


@Override
public boolean onOptionsItemSelected(MenuItem item)
{ switch ([Link]()) {
case [Link].menu_home:
[Link]("Home selected");
[Link](this, "You selected Home", Toast.LENGTH_SHORT).show();
return true;

case [Link].menu_settings:
[Link]("Settings selected");
[Link](this, "You selected Settings", Toast.LENGTH_SHORT).show();
return true;

case [Link].menu_about:
[Link]("About selected");
[Link](this, "You selected About", Toast.LENGTH_SHORT).show();
return true;

default:
return [Link](item);
}
}
}
Step 4: [Link]
<manifest xmlns:android="[Link]
package="[Link]">

<application
android:allowBackup="true"
android:label="Menu Example"
android:supportsRtl="true"
android:theme="@style/[Link]">

<activity android:name=".MainActivity">
<intent-filter>
<action android:name="[Link]" />
<category android:name="[Link]" />
</intent-filter>
</activity>

</application>
</manifest>

OUTPUT Select an option from the menu

When you tap the 3-dot menu (⋮) or Action Bar icons:

Home
Settings
About

When selecting each item:

• Home → Toast: “You selected Home”


TextView: “Home selected”
• Settings → Toast: “You selected Settings”
TextView: “Settings selected”
• About → Toast: “You selected About”
TextView: “About selected”
Experiment 10
Number
Experiment
Title Create a user registration application that stores the user details in a database table.
Implementation
Step 1: activity_main.xml (Layout File)

This layout contains 3 EditText fields, one Button, and one TextView.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="20dp"
android:gravity="center">

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

<EditText
android:id="@+id/etEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Email"
android:inputType="textEmailAddress"
android:textSize="18sp"
android:layout_marginTop="10dp" />

<EditText
android:id="@+id/etPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Password"
android:inputType="textPassword"
android:textSize="18sp"
android:layout_marginTop="10dp" />

<Button
android:id="@+id/btnRegister"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Register"
android:layout_marginTop="20dp" />
<TextView
android:id="@+id/tvStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:textSize="18sp"
android:textColor="@android:color/black" />

</LinearLayout>
Step 2: [Link]

This is the main activity that handles the registration logic.

package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity

{ EditText etName, etEmail, etPassword;


Button btnRegister;
TextView tvStatus;
DatabaseHelper dbHelper;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

etName = findViewById([Link]);
etEmail = findViewById([Link]);
etPassword = findViewById([Link]);
btnRegister =
findViewById([Link]); tvStatus =
findViewById([Link]);

dbHelper = new DatabaseHelper(this);

[Link](new [Link]() {
@Override
public void onClick(View view) {
String name = [Link]().toString();
String email = [Link]().toString();
String password = [Link]().toString();

if ([Link]() || [Link]() || [Link]())


{ [Link]([Link], "Please fill all fields",
Toast.LENGTH_SHORT).show();
} else {
boolean isInserted = [Link](name, email, password);
if (isInserted) {
[Link]("User Registered Successfully!");
[Link]([Link], "Registration Successful",
Toast.LENGTH_SHORT).show();
} else {
[Link]("Registration Failed!");
}
}
}
});
}
}
Step 3: [Link] (SQLite Database Class)

This file handles database creation and data insertion.

package [Link];

import [Link];
import [Link];
import [Link];
import [Link];

public class DatabaseHelper extends SQLiteOpenHelper {

private static final String DATABASE_NAME = "UserDB";


private static final int DATABASE_VERSION = 1;
private static final String TABLE_NAME =
"users"; private static final String COL_ID = "id";
private static final String COL_NAME = "name";
private static final String COL_EMAIL = "email";
private static final String COL_PASSWORD = "password";

public DatabaseHelper(Context context) {


super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

@Override
public void onCreate(SQLiteDatabase db) {
String CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + "("
+ COL_ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"
+ COL_NAME + " TEXT,"
+ COL_EMAIL + " TEXT,"
+ COL_PASSWORD + " TEXT)";
[Link](CREATE_TABLE);
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{ [Link]("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}

public boolean insertUser(String name, String email, String password)


{ SQLiteDatabase db = [Link]();
ContentValues values = new ContentValues();
[Link](COL_NAME, name);
[Link](COL_EMAIL, email);
[Link](COL_PASSWORD, password);
long result = [Link](TABLE_NAME, null, values);
[Link]();
return result != -1; // if result = -1, insertion failed
}
}
Step 4: [Link]

<manifest xmlns:android="[Link]
package="[Link]">

<application
android:allowBackup="true"
android:label="User Registration"
android:supportsRtl="true"
android:theme="@style/[Link]">

<activity android:name=".MainActivity">
<intent-filter>
<action android:name="[Link]" />
<category android:name="[Link]" />
</intent-filter>
</activity>

</application>
</manifest>

OUTPUT Enter Name: [Ankita]


Enter Email: [ankita@[Link]]
Enter Password:[12345]
[ Register ]

After Clicking Register

Toast: “Registration Successful”


TextView Output: “User Registered Successfully!”

You might also like