0% found this document useful (0 votes)
89 views6 pages

14 Aneesh Mad 11

The document discusses creating checkboxes in Android. It provides the XML code to create multiple checkboxes with different labels. It also provides the Java code to check which checkboxes are selected when a button is clicked and display a toast notification with the selected label. The checkboxes are placed in a linear layout along with a button. On click of the button, it checks the status of each checkbox and displays a toast if that checkbox is selected.
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)
89 views6 pages

14 Aneesh Mad 11

The document discusses creating checkboxes in Android. It provides the XML code to create multiple checkboxes with different labels. It also provides the Java code to check which checkboxes are selected when a button is clicked and display a toast notification with the selected label. The checkboxes are placed in a linear layout along with a button. On click of the button, it checks the status of each checkbox and displays a toast if that checkbox is selected.
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/ 6

Practical 11

Xi. Practical Related Questions


1. Name the different methods of checkbox
Ans -: Methods of Checkbox are as follows -:
Public Boolean isChecked()
Public void setChecked(Boolean status)

2. List the different attributes of Checkboxes


Ans -: Attributes of Checkbox are as follows -:
Android:autoText
Android:drawableButton
Android:drawableRight
Android:editable
Android:Text
Android:background
Android:ContentDescription
Android:id
Android:Layout

3. Write XML Tag to Create a Checkbox named “Android”


Ans -:
<CheckBox
android:id="@+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Android"
tools:layout_editor_absoluteX="254dp"
tools:layout_editor_absoluteY="112dp" />

X.Exercise
1. Write a program to Show the checkboxes and toast selected checkboxes
Ans -:
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="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:layout_editor_absoluteX="195dp"
tools:layout_editor_absoluteY="101dp">

<CheckBox
android:id="@+id/c1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Aneesh"
tools:layout_editor_absoluteX="16dp"
tools:layout_editor_absoluteY="32dp" />

<CheckBox
android:id="@+id/c2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Chess"
tools:layout_editor_absoluteX="254dp"
tools:layout_editor_absoluteY="32dp" />

<CheckBox
android:id="@+id/c3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Singing"
tools:layout_editor_absoluteX="16dp"
tools:layout_editor_absoluteY="112dp" />

<CheckBox
android:id="@+id/c4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Developer"
tools:layout_editor_absoluteX="254dp"
tools:layout_editor_absoluteY="112dp" />

<CheckBox
android:id="@+id/c5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TYCO"
tools:layout_editor_absoluteX="145dp"
tools:layout_editor_absoluteY="200dp" />

<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Click" />
</LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>
Main_Activity.java
package com.example.practical11a;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity{


CheckBox cb1,cb2,cb3,cb4,cb5;
Button b1;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
cb1 = (CheckBox) findViewById(R.id.c1);
cb2 = (CheckBox) findViewById(R.id.c2);
cb3 = (CheckBox) findViewById(R.id.c3);
cb4 = (CheckBox) findViewById(R.id.c4);
cb5 = (CheckBox) findViewById(R.id.c5);
b1 = (Button) findViewById(R.id.button1);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (cb1.isChecked())
{
Toast.makeText(getApplicationContext(),"You Selected
Aneesh",Toast.LENGTH_LONG).show();
}
if(cb2.isChecked())
{
Toast.makeText(getApplicationContext(),"You Selected
Chess",Toast.LENGTH_LONG).show();
}
if(cb3.isChecked())
{
Toast.makeText(getApplicationContext(),"You Selected
Singing",Toast.LENGTH_LONG).show();
}
if(cb4.isChecked())
{
Toast.makeText(getApplicationContext(),"You Selected
Developer",Toast.LENGTH_LONG).show();
}
if(cb5.isChecked())
{
Toast.makeText(getApplicationContext(),"You Selected
TYCO",Toast.LENGTH_LONG).show();
}
}
});
}
}
Output

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy