Mobile Programming
Mobile Programming
LAB REPORT
Submitted to
Submitted by
Sixth Semester
February 2026
Declaration
I hereby declare that this is my original work prepared as per the guidelines provided
by our course instructor Er. Samarajya Shrestha. I have tried my best to be as creative
as possible during the preparation of lab reports presented herewith. I have not
submitted these writings to any other institution or for any other degrees.
Signature:
II
Letter of Recommendation
This is to certify that this Lab Report is an academic work done by Aryan Adhikari,
submitted in the partial fulfilment of the requirements for the degree of Bachelors in
Computer Application at Faculties of Humanities and Social Science, Tribhuvan
University under my guidance and supervision. To the best of my knowledge, the
work performed by him in the Lab Report is his own creation.
III
Table of Contents
1: THE ANDROID MANIFEST FILE..................................................................................................1
2: INTENT FILTERS..............................................................................................................................2
3: ANDROID LAYOUTS........................................................................................................................3
LINEARLAYOUT.....................................................................................................................................3
RELATIVELAYOUT.................................................................................................................................3
CONSTRAINTLAYOUT.............................................................................................................................4
TABLELAYOUT.......................................................................................................................................5
GRIDLAYOUT.........................................................................................................................................5
FRAMELAYOUT......................................................................................................................................6
4: ANDROID WIDGETS........................................................................................................................7
TEXTVIEW.............................................................................................................................................7
EDITTEXT...............................................................................................................................................8
BUTTON..................................................................................................................................................8
CHECKBOX............................................................................................................................................9
RADIOBUTTON / RADIOGROUP............................................................................................................10
SPINNER...............................................................................................................................................10
5: ANDROID MENUS...........................................................................................................................12
OPTIONS MENU....................................................................................................................................12
CONTEXT MENU..................................................................................................................................12
POPUP MENU.......................................................................................................................................13
INTRODUCTION.....................................................................................................................................14
OBJECTIVES..........................................................................................................................................14
TOOLS & REQUIREMENTS....................................................................................................................14
SYSTEM DESIGN...................................................................................................................................14
WORKING OF THE APPLICATION..........................................................................................................15
CODE AND OUTPUT..............................................................................................................................15
1: The Android Manifest File
The [Link] file is the control center of every Android application. It
acts as a comprehensive blueprint, providing essential information to the Android
system about the app's components, capabilities, and requirements.
Critical Components
Example
1
2
2: Intent Filters
An Intent Filter is a powerful mechanism in Android that declares the capabilities of
an app component (Activity, Service, or BroadcastReceiver) and specifies what types
of Intents it can respond to. It is how the Android system knows which app or
component should handle a specific request or piece of data. For example, if a user
clicks a web link, an Intent Filter helps the system decide which browser app should
open it.
Uses
- Primarily defined inside <activity>, <service>, and <receiver> tags within the
[Link].
- They empower the app to receive explicit (targeted) and implicit (general
broadcast) Intents.
- Essential for enabling seamless interaction between our app and other apps, or
the Android system itself.
Key Elements
Example
3
3: Android Layouts
Layouts in Android define the structure and arrangement of user interface (UI)
components on the screen. They act as containers that hold widgets such as TextView,
Button, and EditText. Layouts are defined using XML tags inside the
activity_main.xml file.
LinearLayout
LinearLayout arranges its child elements in a single direction, either vertical or
horizontal. An important attribute is android:orientation=”vertical” or “horizontal”
Example
4
RelativeLayout
RelativeLayout positions elements relative to parent or other views. It allows flexible
UI design without nesting multiple layouts.
Important Attributes
- android:layout_below
- android:layout_above
- android:layout_toRightOf
- android:layout_alignParentTop
- android:layout_centerInParent
5
Example
ConstraintLayout
ConstraintLayout is a flexible and modern layout that positions elements using
constraints. Some important attributes are app:layout_constraintTop_toTopOf,
app:layout_constraintStart_toStartOf, app:layout_constraintEnd_toEndOf and
app:layout_constraintBottom_toBottomOf.
Example
6
7
TableLayout
TableLayout arranges Ui elements in rows and columns using <TableRow>. Some
important attributes are android:stretchColumns and android:collapseColumns.
Example
GridLayout
GridLayout arranges the elements in a grid format of rows and columns. Some
important attributes are android:rowCount and android:columnCount.
Example
8
FrameLayout
FrameLayout is designed to display a single view on top of another. It is often used
for fragments. An important attribute is android:layout_gravity.
Example
9
4: Android Widgets
Widgets are UI components that allow users to interact with an Android application.
They are the building blocks of the user interface and are placed inside Layouts such
as LinearLayout or ConstraintLayout. Each widget performs a specific function such
as displaying text, taking input, or triggering actions.
TextView
TextView is used to display any text on the screen.
Important Attributes
- android:id
- android:text
- android:textSize
- android:textColor
- android:gravity
Example
10
EditText
EditText allows users to enter text input.
Important Attributes
- android:id
- android:hint
- android:inputType
- android:maxLength
Example
Button
Button is used to perform an action when it is clicked by the user.
Important Attributes
- android:id
- android:text
- android:onClick
- android:background
11
Example
CheckBox
Checkbox allows users to select multiple options from list of available options.
Important Attributes
- android:id
- android:text
- android:checked
Example
12
RadioButton / RadioGroup
RadioButton allows uses to select one option among many available options. It is used
inside RadioGroup
Important Attributes
- android:id
- android:text
- android:checked
Example
Spinner
Spinner provides a drop-down list for selecting one item.
Important Attributes
- android:id
- android:entries
- android:spinnerMode
13
Example
14
5: Android Menus
Menus in Android provide a way to present options and actions to users. They allow
users to interact with the application efficiently. Android supports different types of
menus such as Options Menu, Context Menu, and Popup Menu.
Options Menu
Options Menu appears in the app bar (three dots menu). It contains global actions for
the activity.
Example:
Context Menu
Context Menu appears when the user long-presses a view.
Example:
15
Popup Menu
Popup Menu appears anchored to a specific view.
Example:
16
6: Android Application with Database Integration
Introduction
This project demonstrates the development of a complete registration system in
Android. The application collects user information such as name, email, phone
number, gender, and course. The entered data is validated and stored locally using
SQLite database. The application also provides functionality to display and delete
stored records.
Objectives
- To design a user-friendly registration form.
- To implement input validation.
- To create and manage SQLite database using SQLiteOpenHelper.
- To insert data into database.
- To retrieve and display stored data.
- To delete records from database.
System Design
UI Components Used
17
18
This application consists of two activities:
19
app:layout_constraintTop_toBottomOf="@id/etName"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="12dp"/>
<EditText
android:id="@+id/etPhone"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="Phone"
android:inputType="phone"
android:maxLength="15"
app:layout_constraintTop_toBottomOf="@id/etEmail"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="12dp"/>
<TextView
android:id="@+id/tvGender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Gender"
android:textStyle="bold"
app:layout_constraintTop_toBottomOf="@id/etPhone"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginTop="16dp"/>
<RadioGroup
android:id="@+id/rgGender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/tvGender"
app:layout_constraintStart_toStartOf="parent">
<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:id="@+id/tvCourse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Course"
android:textStyle="bold"
app:layout_constraintTop_toBottomOf="@id/rgGender"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginTop="16dp"/>
<Spinner
android:id="@+id/spCourse"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/tvCourse"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="8dp"/>
<CheckBox
android:id="@+id/cbAgree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I agree to the terms"
app:layout_constraintTop_toBottomOf="@id/spCourse"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginTop="16dp"/>
20
<Button
android:id="@+id/btnRegister"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Register"
app:layout_constraintTop_toBottomOf="@id/cbAgree"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="16dp"/>
<Button
android:id="@+id/btnView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="View Registered Users"
app:layout_constraintTop_toBottomOf="@id/btnRegister"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="12dp"/>
</[Link]>
21
activity_view_users.xml
<LinearLayout
xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/registered_users"
android:layout_marginTop="20dp"
android:textSize="22sp"
android:textStyle="bold"
android:layout_marginBottom="10dp" />
<ListView
android:id="@+id/lvUsers"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
22
[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class DBHelper extends SQLiteOpenHelper {
private static final String DB_NAME = "registration_db";
private static final int DB_VERSION = 1;
public static final String TABLE_USERS = "users";
public static final String COL_ID = "id";
public static final String COL_NAME = "name";
public static final String COL_EMAIL = "email";
public static final String COL_PHONE = "phone";
public static final String COL_GENDER = "gender";
public static final String COL_COURSE = "course";
public DBHelper(Context context) {
super(context, DB_NAME, null, DB_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
String create =
"CREATE TABLE " + TABLE_USERS + " (" +
COL_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
COL_NAME + " TEXT NOT NULL, " +
COL_EMAIL + " TEXT NOT NULL, " +
COL_PHONE + " TEXT NOT NULL, " +
COL_GENDER + " TEXT NOT NULL, " +
COL_COURSE + " TEXT NOT NULL" +
")";
[Link](create);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
[Link]("DROP TABLE IF EXISTS " + TABLE_USERS);
onCreate(db);
}
public long insertUser(String name, String email, String phone, String gender, String
course) {
SQLiteDatabase db = [Link]();
ContentValues cv = new ContentValues();
[Link](COL_NAME, name);
[Link](COL_EMAIL, email);
[Link](COL_PHONE, phone);
[Link](COL_GENDER, gender);
[Link](COL_COURSE, course);
return [Link](TABLE_USERS, null, cv);
}
public Cursor getAllUsers() {
SQLiteDatabase db = [Link]();
return [Link]("SELECT * FROM " + TABLE_USERS + " ORDER BY " + COL_ID + "
DESC", null);
}
23
public int deleteUserById(int id) {
SQLiteDatabase db = [Link]();
return [Link](TABLE_USERS, COL_ID + "=?", new String[]{[Link](id)});
}
}
[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 etName, etEmail, etPhone;
RadioGroup rgGender;
Spinner spCourse;
CheckBox cbAgree;
Button btnRegister, btnView;
DBHelper db;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
db = new DBHelper(this);
etName = findViewById([Link]);
etEmail = findViewById([Link]);
etPhone = findViewById([Link]);
rgGender = findViewById([Link]);
spCourse = findViewById([Link]);
cbAgree = findViewById([Link]);
btnRegister = findViewById([Link]);
btnView = findViewById([Link]);
List<String> courses = [Link]("Select Course", "BCA", "BIT", "CSIT", "BIM",
"BBS");
ArrayAdapter<String> adapter = new ArrayAdapter<>(
this, [Link].simple_spinner_dropdown_item, courses
);
[Link](adapter);
[Link](v -> registerUser());
[Link](v -> {
Intent i = new Intent([Link], [Link]);
startActivity(i);
});
}
private void registerUser() {
String name = [Link]().toString().trim();
String email = [Link]().toString().trim();
String phone = [Link]().toString().trim();
24
int selectedGenderId = [Link]();
String course = [Link]().toString();
if ([Link]()) {
[Link]("Name is required");
[Link]();
return;
}
if ([Link]() || !Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
[Link]("Valid email is required");
[Link]();
return;
}
if ([Link]() || [Link]() < 7) {
[Link]("Valid phone is required");
[Link]();
return;
}
if (selectedGenderId == -1) {
[Link](this, "Please select gender", Toast.LENGTH_SHORT).show();
return;
}
if ([Link]("Select Course")) {
[Link](this, "Please select a course", Toast.LENGTH_SHORT).show();
return;
}
if (![Link]()) {
[Link](this, "You must agree to the terms",
Toast.LENGTH_SHORT).show();
return;
}
RadioButton rb = findViewById(selectedGenderId);
String gender = [Link]().toString();
long result = [Link](name, email, phone, gender, course);
if (result == -1) {
[Link](this, "Registration failed!", Toast.LENGTH_SHORT).show();
} else {
[Link](this, "Registered successfully!", Toast.LENGTH_SHORT).show();
clearForm();
}
}
private void clearForm() {
[Link]("");
[Link]("");
[Link]("");
[Link]();
[Link](0);
[Link](false);
[Link]();
}
}
25
[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link].*;
import [Link];
public class ViewUsersActivity extends AppCompatActivity {
ListView lvUsers;
DBHelper db;
ArrayList<String> displayList = new ArrayList<>();
ArrayList<Integer> idList = new ArrayList<>();
ArrayAdapter<String> adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_view_users);
lvUsers = findViewById([Link]);
db = new DBHelper(this);
adapter = new ArrayAdapter<>(this, [Link].simple_list_item_1, displayList);
[Link](adapter);
loadUsers();
[Link]((parent, view, position, id) -> {
int userId = [Link](position);
int rows = [Link](userId);
if (rows > 0) {
[Link](this, "Deleted!", Toast.LENGTH_SHORT).show();
loadUsers();
} else {
[Link](this, "Delete failed!", Toast.LENGTH_SHORT).show();
}
return true;
});
}
private void loadUsers() {
[Link]();
[Link]();
Cursor c = [Link]();
if ([Link]() == 0) {
[Link]("No users found.");
[Link]();
[Link]();
return;
}
while ([Link]()) {
int id = [Link](0);
String name = [Link](1);
String email = [Link](2);
String phone = [Link](3);
String gender = [Link](4);
String course = [Link](5);
[Link](id);
26
String row = "ID: " + id +
"\nName: " + name +
"\nEmail: " + email +
"\nPhone: " + phone +
"\nGender: " + gender +
"\nCourse: " + course;
[Link](row);
}
[Link]();
[Link]();
}
}
[Link]
<manifest
xmlns:android="[Link]
package="[Link]">
<application
android:icon="@mipmap/ic_launcher_round"
android:label="@string/app_name"
android:allowBackup="true"
android:theme="@style/[Link]">
<activity
android:name=".ViewUsersActivity"
android:exported="false" />
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="[Link]" />
<category android:name="[Link]" />
</intent-filter>
</activity>
</application>
</manifest>
27
Output
28