0% found this document useful (0 votes)
32 views10 pages

Worksheet Template Lab

The document describes an experiment to create an Android app using various controls like EditText, CheckBox, RadioButton, and RadioGroup. It involves designing the user interface in XML layout files with the mentioned controls and writing Java code in the Activity file to add functionality like capturing user input and selections. The app allows selecting weather options using radio buttons, additional options using checkboxes and displays the selection using a toast message on clicking the submit button. Tools required include Android Studio IDE, Android SDK and a physical device or emulator to test the app.
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)
32 views10 pages

Worksheet Template Lab

The document describes an experiment to create an Android app using various controls like EditText, CheckBox, RadioButton, and RadioGroup. It involves designing the user interface in XML layout files with the mentioned controls and writing Java code in the Activity file to add functionality like capturing user input and selections. The app allows selecting weather options using radio buttons, additional options using checkboxes and displays the selection using a toast message on clicking the submit button. Tools required include Android Studio IDE, Android SDK and a physical device or emulator to test the app.
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/ 10

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

Experiment No:2.2

Student Name: Abhinandan Singh Rana UID:21BCS1977


Branch: CSE
Section/Group:616-A
Semester: 6th Date of
Performance:28-2-24
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.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

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.

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

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

 Step 3: Code in main_activity.xml


DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

<?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"
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" />
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

<RadioButton
android:id="@+id/radioButton7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
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"
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.867" />

<Button
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);
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

// Listener for both radio group and checkboxes


CompoundButton.OnCheckedChangeListener
checkedChangeListener = new
CompoundButton.OnCheckedChangeListener() {
@Override
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
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

 Learning Outcomes:
1. Learned about Toast in Android Studio.

You might also like