TY Practical No. 11 Develop a program to implement GridView, ImageView, ScrollView, and ListView for a Hotel Management System
Practical No. 11
Develop a program to implement GridView, ImageView, ScrollView, and ListView for a Hotel Management System
I. Practical Significance
This practical enables students to design dynamic, scrollable Android user interfaces used in real-world management systems. It demonstrates how to display collections of data such as room categories and customer bookings using grid-based and list-based views.
II. Industry / Employer Expected Outcome(s)
Students will be able to:
Implement GridView, ImageView, ScrollView, and ListView
Use adapters to bind data with UI components
Design a basic Hotel Management System interface
III. Course Level Learning Outcome(s)
CO3 – Develop Android applications using UI components and layouts.
IV. Laboratory Learning Outcome(s)
LLO 11.1 – Create Android application to implement different types of views.
V. Relevant Affective Domain Related Outcomes
Promotes confidence in handling dynamic content
Encourages structured UI design and user interaction handling
VI. Relevant Theoretical Background
GridView: Displays items in a two-dimensional scrollable grid (room categories).
ImageView: Displays images such as hotel banners.
ScrollView: Allows vertical scrolling when content exceeds screen height.
ListView: Displays a vertically scrollable list (customer bookings).
Adapters: Bridge between data source and UI components (
ArrayAdapter).View Recycling: Improves performance by reusing item views.
VII. Application Overview
Application Type: Hotel Management System
Displayed Text: “Sanjay Ghodawat Institute, Atigre”
Implemented Views: ScrollView, ImageView, GridView, ListView
VIII. Project File Structure (Tree Diagram)
HotelManagementViews/
│
├── app/
│ └── src/
│ └── main/
│ ├── java/com/example/hotelmanagementviews/
│ │ └── MainActivity.java
│ │
│ ├── res/
│ │ ├── layout/
│ │ │ ├── activity_main.xml
│ │ │ └── grid_item.xml
│ │ │
│ │ ├── drawable/
│ │ │ └── hotel_banner.png
│ │ │
│ │ └── values/
│ │ ├── strings.xml
│ │ └── colors.xml
│ │
│ └── AndroidManifest.xml
IX. XML Layout Code
1️⃣ activity_main.xml
(ScrollView + ImageView + GridView + ListView – corrected and verified)
<?xml version="1.0" encoding="utf-8"?>
<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="16dp">
<!-- Institute Name -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sanjay Ghodawat Institute, Atigre"
android:textSize="20sp"
android:textStyle="bold"
android:gravity="center"
android:padding="8dp" />
<!-- ImageView -->
<ImageView
android:layout_width="match_parent"
android:layout_height="200dp"
android:src="@drawable/hotel_banner"
android:scaleType="centerCrop"
android:contentDescription="Hotel Banner" />
<!-- GridView Title -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Room Categories"
android:textSize="18sp"
android:textStyle="bold"
android:paddingTop="12dp" />
<!-- GridView -->
<GridView
android:id="@+id/gridViewRooms"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:numColumns="2"
android:horizontalSpacing="10dp"
android:verticalSpacing="10dp"
android:stretchMode="columnWidth" />
<!-- ListView Title -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Customer Bookings"
android:textSize="18sp"
android:textStyle="bold"
android:paddingTop="12dp" />
<!-- ListView -->
<ListView
android:id="@+id/listViewCustomers"
android:layout_width="match_parent"
android:layout_height="200dp" />
</LinearLayout>
</ScrollView>
2️⃣ grid_item.xml
(Single GridView item layout)
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="80dp"
android:gravity="center"
android:textSize="16sp"
android:textStyle="bold"
android:background="#DDDDDD"
android:padding="8dp" />
X. Java Code
MainActivity.java
(Adapters + View binding – error-free)
package com.example.hotelmanagementviews;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.ListView;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
GridView gridViewRooms;
ListView listViewCustomers;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gridViewRooms = findViewById(R.id.gridViewRooms);
listViewCustomers = findViewById(R.id.listViewCustomers);
// Data for GridView
String[] roomTypes = {
"Deluxe Room",
"AC Room",
"Non-AC Room",
"Suite Room"
};
// Data for ListView
String[] customers = {
"Customer 1 - Room 101",
"Customer 2 - Room 202",
"Customer 3 - Room 303",
"Customer 4 - Room 404"
};
// GridView Adapter
ArrayAdapter<String> gridAdapter =
new ArrayAdapter<>(this, R.layout.grid_item, roomTypes);
gridViewRooms.setAdapter(gridAdapter);
// ListView Adapter
ArrayAdapter<String> listAdapter =
new ArrayAdapter<>(this,
android.R.layout.simple_list_item_1,
customers);
listViewCustomers.setAdapter(listAdapter);
}
}
