0% found this document useful (0 votes)
66 views9 pages

Worksheet Template Lab

The document describes an experiment conducted by a student to create an Android app using various controls like EditText, CheckBox, RadioButton, and RadioGroup. The app allows users to select weather options like sunny, rainy, cold using radio buttons and additional options like snow and thunder using checkboxes. The student codes the layout of the app interface using XML and adds functionality to the buttons and controls using Java code in Android Studio. The objective is to showcase the usage of different user interface elements and enhance the user experience.
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)
66 views9 pages

Worksheet Template Lab

The document describes an experiment conducted by a student to create an Android app using various controls like EditText, CheckBox, RadioButton, and RadioGroup. The app allows users to select weather options like sunny, rainy, cold using radio buttons and additional options like snow and thunder using checkboxes. The student codes the layout of the app interface using XML and adds functionality to the buttons and controls using Java code in Android Studio. The objective is to showcase the usage of different user interface elements and enhance the user experience.
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/ 9

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

Experiment No:2.2

Student Name: Abhinandan Singh Rana UID:21BCS1977


Branch: CSE Section/Group:616-A
Semester: 6th Semester Date of Performance:28-02-2024
Subject Name: Mad Lab Subject Code:21CSH-355

 Aim: Create an Android App using various controls such TexEdit, CheckBox,
RadioButton, RadioGroup, etc.

 Objective: The objective of an Android app using various controls such as EditText,
CheckBox, RadioButton, and RadioGroup could be to create a user interface that involves
user input, selection, and interaction with different types of controls. This type of app aims
to showcase the usage and functionalities of these UI elements to enhance the user
experience.

 Input/Apparatus Used:
To create an Android app using various controls such as EditText, CheckBox,
RadioButton, and RadioGroup, we need the following tools and resources:
1. Integrated Development Environment (IDE): Android Studio: The official IDE for
Android development. Download and install Android Studio from the official website:
Android Studio.

2. Android SDK: The Android Software Development Kit (SDK) is essential for
developing Android applications. Android Studio usually comes bundled with the SDK,
but you may need to update it through the SDK Manager within Android Studio.

3. Java Development Kit (JDK): Android apps are primarily written in Java or Kotlin.
Make sure you have the Java Development Kit installed. Android Studio supports JDK.
You can download it from the Oracle website: Java SE Downloads.

4. Android Virtual Device (AVD) or Physical Android Device: We need a device to


test your Android application. We can use an emulator (AVD) that comes with Android
Studio or a physical Android device connected to your computer.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

 Procedure:
 Step 1: Select Empty Views Activity.

 Step 2: Name your application and select language as java

 Step 3: Code in main_activity.xml

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


<androidx.constraintlayout.widget.ConstraintLayout
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"
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/silas_baisch_51quglv6en0_unsplash"
tools:context=".MainActivity">

<TextView
android:id="@+id/textView"
android:layout_width="219dp"
android:layout_height="64dp"
android:gravity="center"
android:text="Select the weather"
android:textSize="22sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.086" />

<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="299dp"
android:layout_height="202dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView"
app:layout_constraintVertical_bias="0.102">

<RadioButton
android:id="@+id/radioButton4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="Sunny" />

<RadioButton
android:id="@+id/radioButton6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="Rainy" />

<RadioButton
android:id="@+id/radioButton7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

android:textStyle="bold"
android:text="Coldy" />
</RadioGroup>

<TextView
android:id="@+id/textView1"
android:layout_width="219dp"
android:layout_height="64dp"
android:gravity="center"
android:text="What other options You want in Your Day?"
android:textColor="@color/black"
android:textSize="21dp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.406"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.649" />

<CheckBox
android:id="@+id/checkBox6"
android:layout_width="298dp"
android:layout_height="52dp"
android:text="Snow"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.495"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.762" />

<CheckBox
android:id="@+id/checkBox7"
android:layout_width="294dp"
android:layout_height="51dp"
android:text="Thunder"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.478"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.867" />

<Button
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

android:id="@+id/showDetailsButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/checkBox7"
app:layout_constraintVertical_bias="0.2" />

</androidx.constraintlayout.widget.ConstraintLayout>

 Step 4: Code in ActivityMain.java

package com.example.toast;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


RadioGroup subs;
CheckBox accessories, noAccessories;
RadioButton selectedRadioButton;
Button showDetailsButton;

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

subs = findViewById(R.id.radioGroup);
accessories = findViewById(R.id.checkBox6);
noAccessories = findViewById(R.id.checkBox7);
showDetailsButton = findViewById(R.id.showDetailsButton);

// Listener for both radio group and checkboxes


CompoundButton.OnCheckedChangeListener
checkedChangeListener = new
CompoundButton.OnCheckedChangeListener() {
@Override
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

public void onCheckedChanged(CompoundButton


buttonView, boolean isChecked) {
if (buttonView instanceof RadioButton) {
if (isChecked) {
selectedRadioButton = (RadioButton)
buttonView;
}
}
}
};

// Set listener for radio group


subs.setOnCheckedChangeListener(new
RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int
checkedId) {
selectedRadioButton = findViewById(checkedId);
}
});

// Set listener for accessories checkbox

accessories.setOnCheckedChangeListener(checkedChangeListener);

// Set click listener for show details button


showDetailsButton.setOnClickListener(view -> {
if (selectedRadioButton != null) {
String selectWeather =
selectedRadioButton.getText().toString();
String anythingMessage = accessories.isChecked() ?
"Options Selected" : "No Options selected";
Toast.makeText(MainActivity.this, "Selected Weather: "
+ selectWeather + "\n" + anythingMessage,
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(MainActivity.this, "Please select a
Weather", Toast.LENGTH_SHORT).show();
}
});
}
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

 Step 5: Connect your Device and check whether device Is detected by the ADV
and hit run
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

 Step 6: application is successfully installed in your device


DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

 Result: On Clicking the Submit Button a TOAST comes up showing the information
 Learning Outcomes:
1. Learned about Toast in Android Studio.

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