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);
}
}