0% found this document useful (0 votes)
318 views2 pages

Practical No 11: City Selection App

This document contains code for an Android application that allows a user to select an Indian city from a list of checkboxes and see a toast message with the selected city name. The activity_main.xml layout contains checkboxes for the cities of Pune, Mumbai, Nagpur, Dhule, and Nashik. The MainActivity class finds the checkbox views and adds the same OnCheckedChangeListener to each one. When a checkbox is checked or unchecked, the listener gets the city name from the checkbox text and displays it in a toast if checked. This allows the user to select one of the cities and see the name of the "Cleanest City".

Uploaded by

atharvabutte03
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)
318 views2 pages

Practical No 11: City Selection App

This document contains code for an Android application that allows a user to select an Indian city from a list of checkboxes and see a toast message with the selected city name. The activity_main.xml layout contains checkboxes for the cities of Pune, Mumbai, Nagpur, Dhule, and Nashik. The MainActivity class finds the checkbox views and adds the same OnCheckedChangeListener to each one. When a checkbox is checked or unchecked, the listener gets the city name from the checkbox text and displays it in a toast if checked. This allows the user to select one of the cities and see the name of the "Cleanest City".

Uploaded by

atharvabutte03
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
  • Activity XML Layout
  • Java Activity Code

Practical No 11

Q1.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<LinearLayout
android:layout_width="306dp"
android:layout_height="442dp"
android:layout_marginStart="52dp"
android:layout_marginTop="92dp"
android:orientation="vertical"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="30dp"
android:text="Select city"
android:textSize="20dp" />

<CheckBox
android:id="@+id/ch1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Pune" />

<CheckBox
android:id="@+id/ch2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Mumbai" />

<CheckBox
android:id="@+id/ch3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Nagpur" />

<CheckBox
android:id="@+id/ch4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Dhule" />

<CheckBox
android:id="@+id/ch5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Nashik" />
</LinearLayout>

<EditText
android:layout_width="162dp"
android:layout_height="48dp"
android:ems="10"
android:inputType="textPersonName"
android:text="Atharva Butte"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

</[Link]>
[Link]
package [Link].practical11;

import [Link];

import [Link];
import [Link].*;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
CheckBox ch1 = findViewById([Link].ch1);
CheckBox ch2 = findViewById([Link].ch2);
CheckBox ch3 = findViewById([Link].ch3);
CheckBox ch4 = findViewById([Link].ch4);
CheckBox ch5 = findViewById([Link].ch5);

[Link] ch_listner = new


[Link]() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
int id = [Link]();
String city = "";
if(id == [Link].ch1 && isChecked)
city = [Link]().toString();
else if (id == [Link].ch2 && isChecked) {
city = [Link]().toString();
} else if (id == [Link].ch3 && isChecked) {
city = [Link]().toString();
}else if (id == [Link].ch4 && isChecked) {
city = [Link]().toString();
} else if (id == [Link].ch5 && isChecked) {
city = [Link]().toString();
}else {

}
if (isChecked)
[Link]([Link],

"Cleanest City is "+city,Toast.LENGTH_LONG).show();


}
};

[Link](ch_listner);
[Link](ch_listner);
[Link](ch_listner);
[Link](ch_listner);
[Link](ch_listner);
}
}

Practical No 11 
Q1. 
activity_main.xml 
<?xml version="1.0" encoding="utf-8"?> 
<androidx.constraintlayout.widget.Constraint
MainActivity.java 
package com.example.practical11; 
 
import androidx.appcompat.app.AppCompatActivity; 
 
import android.o

You might also like