0% found this document useful (0 votes)
29 views

MAD LAB Report 02

This lab report describes implementing a ListView in Android Studio to display added text items. The XML layout defines UI components like an EditText, two buttons, and a ListView. The Java code gets references to these components, adds an onClickListener to the "Add" button to retrieve the text and add it to an ArrayList bound to the ListView using an ArrayAdapter. When tested, the application allowed users to successfully input text, add it to the dynamically updating ListView, and return to the previous page by clicking the "Back" button.

Uploaded by

ziaul hoq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

MAD LAB Report 02

This lab report describes implementing a ListView in Android Studio to display added text items. The XML layout defines UI components like an EditText, two buttons, and a ListView. The Java code gets references to these components, adds an onClickListener to the "Add" button to retrieve the text and add it to an ArrayList bound to the ListView using an ArrayAdapter. When tested, the application allowed users to successfully input text, add it to the dynamically updating ListView, and return to the previous page by clicking the "Back" button.

Uploaded by

ziaul hoq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Green University of Bangladesh

Department of Computer Science and Engineering (CSE)


Faculty of Sciences and Engineering
Semester: (Spring, Year:2023), B.Sc. in CSE (Day/Eve)

LAB REPORT: 2
Course Title: Mobile Application Development Laboratory
Course Code: CSE-426 Section: DA

Student Details

Name ID

1. Ziaul Hoq 202902021

Submission Date: _ _ _ _ _ _ _ _ _ 7-6-23_ _ _ _ _ _ _ _ _ _ _ _ _ _ _


Course Teacher’s Name: _ _ _ _ Md. Shihab Hossain _ _ _ _ _ _ _ _

[For Teachers use only: Don’t Write Anything inside this box]

Project Proposal Status


Marks: ………………………………… Signature: .....................
Comments: .............................................. Date: ..............................
1. TITLE:
Implementation of ListView in Android Studio.

2. OBJECTIVES:
The objective of this lab exercise is to create a simple Android application with a user
interface that includes an EditText field, two buttons, and a ListView. The EditText field
allows the user to enter text, and the "Add" button adds the entered text to the ListView.
The "Back" button takes the user back to the previous page. The lab aims to demonstrate
basic UI components and event handling in Android development.
3. PROCEDURE:
The procedure involved in this lab report includes the following steps for xml code and
java code:
1. The layout file defines the user interface components using a LinearLayout as the root
view.
2. The EditText component (edtext) allows the user to input text.
3. Two buttons (btn1 and btn2) are included. The "Add" button adds the text from the
EditText to the ListView, and the "Back" button returns the user to the previous page.
4. The ListView component (list) displays the added items.
5. The Secondpage class extends the AppCompatActivity class, representing the activity
for the second page of the application.
6. Various variables are declared to represent the UI components, including edtext
(EditText), btn1 and btn2 (Buttons), list (ListView), list1 (ArrayList<String>), and
adapter (ArrayAdapter<String>).
7. In the Oncreate() method , the layout using setContentView
(R.layout.activity.secondpage)
8. References to the UI components are obtained using findViewById() and assigned to
their respective variables.
9. An ArrayList (list1) is initialized to store the entered text items, and an ArrayAdapter
(adapter) is created to bind the ArrayList to the ListView.
10. An onClickListener is added to the "Add" button (btn1) to handle the click event.
When the button is clicked, the text from the EditText is retrieved, added to the
ArrayList (list1), and the adapter is notified of the data change.
11. Finally, the adapter is set to the ListView to display the updated items.

4. IMPLEMENTATION:
XML CODE:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
tools:context=".Secondpage">

<EditText
android:id="@+id/edtext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Text Here"
android:layout_margin="30dp"
/>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add"
android:layout_marginRight="30dp"/>

<Button
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="80dp"
android:text="Back"/>

</LinearLayout>

<ListView
android:id="@+id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>

JAVA CODE:
package com.example.homepage;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;

import java.util.ArrayList;

public class Secondpage extends AppCompatActivity {


EditText edtext;
Button btn1, btn2;
ListView list;
ArrayList<String>list1;
ArrayAdapter<String>adapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_secondpage);

edtext = (EditText)findViewById(R.id.edtext);
btn1 = (Button)findViewById(R.id.btn1);
btn2 = (Button)findViewById(R.id.btn2);
list = (ListView) findViewById(R.id.list);

list1 = new ArrayList<String>();


adapter = new ArrayAdapter<String>(getApplicationContext(),
android.R.layout.simple_list_item_1, list1);

btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String name = edtext.getText().toString();
list1.add(name);
list.setAdapter(adapter);
adapter.notifyDataSetChanged();
}
});

}
}

5. In the Java code:


 The Java code defines the behavior and functionality of the user interface components.
 In the onCreate() method, the layout is set and references to UI components are obtained.
 An ArrayList and an ArrayAdapter are created to store and display the entered text items.
 An onClickListener is added to the "Add" button to handle the addition of items to the
list.
 When the button is clicked, the text from the EditText is retrieved, added to the
ArrayList, and the adapter is notified to update the ListView.
 The updated adapter is set to the ListView for displaying the added items.

6. In the XML layout:


 The XML layout defines the structure and appearance of the user interface components.
 A LinearLayout is used as the root view with vertical orientation.
 An EditText component is provided for text input.
 Two buttons (Add and Back) are included within a horizontal LinearLayout.
 A ListView is used to display the added items.

7. OUTPUT:
During testing, the implemented code successfully achieved the desired functionality. The
application launched the second page with the provided user interface components. The
"Add" button successfully added the entered text to the ListView, which dynamically
updated to display the newly added items. The "Back" button returned the user to the
previous page without any issues.
8. DISCUSSION
The implemented code demonstrates a basic Android application that incorporates user
interface components such as EditText, Buttons, and ListView. It showcases the use of
event handling and data binding through the use of onClickListener and ArrayAdapter. The
application allows users to input text, add it to a list, and view the updated list of items.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy