Introduction
This article explains Checkboxes in Android. Android Studio is used to create the sample.
CheckBox
A CheckBox is a type of two-state button that can either be checked or unchecked.
In this article I used three CheckBoxes that, when clicked, display a toast that contains the id of that checkbox. If you check the first checkBox then it displays checkbox1 and if you check the second CheckBox then the toast displays checkbox2. I have also used a button so when clicking the button the state of the checkboxes display on the screen that shows which TextBox is selected. If one TextBox is selected then it shows checkbox1:true and another with false. If all the checkboxes are selected then it shows checkbox1:true, checkbox2:true, checkbox3:true.
Step 1
Create a project like this:
Step 2
Create an XML file and the following.

In this, I used three checkboxes and a button that show the state of all the checkboxes on a click.
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:paddingLeft="@dimen/activity_horizontal_margin"
- android:paddingRight="@dimen/activity_horizontal_margin"
- android:paddingTop="@dimen/activity_vertical_margin"
- android:paddingBottom="@dimen/activity_vertical_margin"
- tools:context=".MainActivity"
- android:background="#83a697">
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Check Box Example"
- android:layout_centerHorizontal="true"
- android:textStyle="bold"
- android:textColor="#00ffff"
- android:textSize="30dp" />
- <CheckBox
- android:id="@+id/checkbox1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginTop="70dp"
- android:text="Check1"
- android:textStyle="bold"
- android:textColor="#00ffff" />
- <CheckBox
- android:id="@+id/checkbox2"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginTop="140dp"
- android:text="Check2"
- android:textStyle="bold"
- android:textColor="#00ffff" />
- <CheckBox
- android:id="@+id/checkbox3"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginTop="210dp"
- android:text="Check3"
- android:textStyle="bold"
- android:textColor="#00ffff" />
- <Button
- android:layout_width="wrap_content"
- android:id="@+id/buttonDelete"
- android:layout_height="wrap_content"
- android:layout_marginTop="300dp"
- android:layout_centerHorizontal="true"
- android:textColor="#00ffff"
- android:text="Show Message" />
- </RelativeLayout>



Gowtham RajamanickamPosted Apr 7, 2016, 4:28 AM
Good Show.