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

Practical No. 11

The document outlines an Android application that displays five checkboxes for programming languages and a submit button. When the button is clicked, the selected checkboxes are displayed as a toast message. The layout and functionality are defined in XML and Java code respectively.

Uploaded by

ganeshkumbhar638
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)
4 views2 pages

Practical No. 11

The document outlines an Android application that displays five checkboxes for programming languages and a submit button. When the button is clicked, the selected checkboxes are displayed as a toast message. The layout and functionality are defined in XML and Java code respectively.

Uploaded by

ganeshkumbhar638
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

Q.

Write a program to show five


checkboxes and toast selected checkboxes. android:layout_marginHorizontal="30dp"
android:textSize="20dp"
Activity_main.xml
/>
<?xml version="1.0" encoding="utf-8"?> <CheckBox
<LinearLayout android:id="@+id/checkBox3"
xmlns:android="http://schemas.android.com/a android:layout_width="match_parent"
pk/res/android" android:layout_height="wrap_content"
android:text="PHP"
xmlns:app="http://schemas.android.com/apk/r
es-auto" android:layout_marginHorizontal="30dp"
android:textSize="20dp"
xmlns:tools="http://schemas.android.com/tool />
s" <CheckBox
android:id="@+id/main" android:id="@+id/checkBox4"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"
tools:context=".MainActivity" android:text="Python"
android:orientation="vertical"
android:paddingHorizontal="20dp" android:layout_marginHorizontal="30dp"
android:gravity="center" android:textSize="20dp"
> />
<CheckBox
<TextView android:id="@+id/checkBox5"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Select Programming android:text="MAD"
language"
android:textSize="25dp"/> android:layout_marginHorizontal="30dp"
android:textSize="20dp"
/>
<CheckBox <Button
android:id="@+id/checkBox1" android:layout_width="wrap_content"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_height="wrap_content" android:text="Submit"
android:text="Java" android:onClick="display"
android:paddingHorizontal="30dp"
android:layout_marginHorizontal="30dp" android:layout_marginTop="20dp"
android:textSize="20dp" />
/>
<CheckBox </LinearLayout>
android:id="@+id/checkBox2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="C++"
MainActivity.java result = result.substring(0,
result.length() - 1);
package com.example.practicalno11_1; Toast.makeText(this, result,
Toast.LENGTH_SHORT).show();
import }
androidx.appcompat.app.AppCompatActivity;
}
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.Toast;

public class MainActivity extends


AppCompatActivity {
CheckBox c1, c2, c3, c4, c5;

@Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

public <string> void display(View v) {


String result = "Your selected items are:
";
c1 = (CheckBox)
findViewById(R.id.checkBox1);
c2 = (CheckBox)
findViewById(R.id.checkBox2);
c3 = (CheckBox)
findViewById(R.id.checkBox3);
c4 = (CheckBox)
findViewById(R.id.checkBox4);
c5 = (CheckBox)
findViewById(R.id.checkBox5);
if (c1.isChecked()) {
result += c1.getText().toString() + ",";
}
if (c2.isChecked()) { }
result += c2.getText().toString() + ",";
}
if (c3.isChecked()) {
result += c3.getText().toString() + ",";
}
if (c4.isChecked()) {
result += c4.getText().toString() + ",";
}
if (c5.isChecked()) {
result += c5.getText().toString() + ",";
}
if (result != null) {

You might also like