Practical No 11
Practical No 11
Q1.
activity_main.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"
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" />
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
package com.example.practical11;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.*;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
CheckBox ch1 = findViewById(R.id.ch1);
CheckBox ch2 = findViewById(R.id.ch2);
CheckBox ch3 = findViewById(R.id.ch3);
CheckBox ch4 = findViewById(R.id.ch4);
CheckBox ch5 = findViewById(R.id.ch5);
}
if (isChecked)
Toast.makeText(MainActivity.this,
ch1.setOnCheckedChangeListener(ch_listner);
ch2.setOnCheckedChangeListener(ch_listner);
ch3.setOnCheckedChangeListener(ch_listner);
ch4.setOnCheckedChangeListener(ch_listner);
ch5.setOnCheckedChangeListener(ch_listner);
}
}