100% found this document useful (1 vote)
158 views2 pages

Practical 11 PDF

The document describes a program to implement checkboxes in Android. It includes the XML layout code to display 5 checkboxes and a submit button. The Java code finds the checkbox and button views, adds an onclick listener to the button to check which checkboxes are selected and display them in a toast message. When the button is clicked, it loops through each checkbox, checks if it is selected, and adds the text to a string to display in the toast.

Uploaded by

Ajinkya Patil
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
100% found this document useful (1 vote)
158 views2 pages

Practical 11 PDF

The document describes a program to implement checkboxes in Android. It includes the XML layout code to display 5 checkboxes and a submit button. The Java code finds the checkbox and button views, adds an onclick listener to the button to check which checkboxes are selected and display them in a toast message. When the button is clicked, it loops through each checkbox, checks if it is selected, and adds the text to a string to display in the toast.

Uploaded by

Ajinkya Patil
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/ 2

Practical No. 11 : Develop a program to implement Checkbox.

Name: Ajinkya P. Patil Class: TYCM-II Roll No.: 39

1. Write a Program to show five checkboxes and toast selected checkboxes.

activity_main.xml Code:
<?xml version="1.0" encoding="utf-8"?> android:layout_width="90dp"
<LinearLayout android:layout_height="60dp"
xmlns:android="http://schemas.android.com/a android:textSize="20dp"
pk/res/android" android:gravity="center"
android:layout_gravity="center"
xmlns:app="http://schemas.android.com/apk/r android:text="MAD" />
es-auto"
<CheckBox
xmlns:tools="http://schemas.android.com/too android:id="@+id/ch4"
ls" android:layout_margin="2dp"
android:layout_width="match_parent" android:layout_width="90dp"
android:layout_height="match_parent" android:layout_height="70dp"
android:orientation="vertical" android:textSize="20dp"
tools:context=".MainActivity"> android:gravity="center"
android:layout_gravity="center"
<TextView android:text="WBP" />
android:layout_width="wrap_content"
<CheckBox
android:layout_height="wrap_content" android:id="@+id/ch5"
android:text="Select Subjects : " android:layout_margin="2dp"
android:textSize="40dp" android:layout_width="90dp"
android:gravity="center" android:layout_height="60dp"
android:layout_gravity="center" android:textSize="20dp"
/> android:gravity="center"
android:layout_gravity="center"
<CheckBox android:text="PWP" />
android:id="@+id/ch1"
android:textSize="20dp" <CheckBox
android:layout_margin="2dp" android:id="@+id/ch6"
android:layout_width="90dp" android:layout_margin="2dp"
android:layout_height="60dp" android:layout_width="90dp"
android:gravity="center" android:layout_height="60dp"
android:layout_gravity="center" android:textSize="20dp"
android:text="PWP" /> android:gravity="center"
android:layout_gravity="center"
<CheckBox android:text="ETI" />
android:id="@+id/ch2"
android:layout_margin="2dp" <Button
android:layout_width="90dp" android:id="@+id/b1"
android:layout_height="60dp" android:layout_width="160dp"
android:textSize="20dp" android:layout_height="70dp"
android:gravity="center" android:layout_gravity="center"
android:layout_gravity="center" android:layout_margin="10dp"
android:text="MGT" /> android:gravity="center"
android:text="submit" />
<CheckBox
android:id="@+id/ch3" </LinearLayout>
android:layout_margin="2dp"

MainActivity.java Code:

package com.example.practical_11;
public class MainActivity extends
import AppCompatActivity {
androidx.appcompat.app.AppCompatActivity;
@Override
import android.os.Bundle; protected void onCreate(Bundle
import android.view.View; savedInstanceState) {
import android.widget.Button; super.onCreate(savedInstanceState);
import android.widget.CheckBox;
import android.widget.Toast; setContentView(R.layout.activity_main);
CheckBox ch1 = (CheckBox) {
findViewById(R.id.ch1); s1 =
CheckBox ch2 = (CheckBox) s1+ch3.getText().toString() +"\n";
findViewById(R.id.ch2); }
CheckBox ch3 = (CheckBox)
findViewById(R.id.ch3); if(ch4.isChecked())
CheckBox ch4 = (CheckBox) {
findViewById(R.id.ch4); s1 =
CheckBox ch5 = (CheckBox) s1+ch4.getText().toString() +"\n";
findViewById(R.id.ch5); }
CheckBox ch6 = (CheckBox)
findViewById(R.id.ch6); if(ch5.isChecked())
Button b1 = (Button) {
findViewById(R.id.b1); s1 =
s1+ch5.getText().toString() +"\n";
b1.setOnClickListener(new }
View.OnClickListener() {
@Override if(ch6.isChecked())
public void onClick(View v) { {
String s1 =""; s1 =
if(ch1.isChecked()) s1+ch6.getText().toString() +"\n";
{ }
s1 =
s1+ch1.getText().toString() +"\n";
} Toast.makeText(getApplicationContext(),
"Selected Subjects"+s1,
if(ch2.isChecked()) Toast.LENGTH_SHORT).show();
{ }
s1 = });
s1+ch2.getText().toString() +"\n";
} }
}
if(ch3.isChecked())

Output:

You might also like