Android CheckBox

Categories: Android // Tags: , .
Email this to someonePrint this pageShare on Google+0Share on Facebook6Tweet about this on TwitterShare on LinkedIn0Share on Reddit0Pin on Pinterest0Share on StumbleUpon1
  • Android CheckBox is a type of two state button either checked or unchecked.
  • There can be a lot of usage of checkboxes. For example, it can be used to know the hobby of the user, activate/deactivate the specific action etc.
  • Android CheckBox class is the subclass of CompoundButton class.

Android CheckBox class

The android.widget.CheckBox class provides the facility of creating the CheckBoxes.

Methods of CheckBox class

There are many inherited methods of View, TextView, and Button classes in the CheckBox class. Some of them are as follows:

Method Description
public boolean isChecked() Returns true if it is checked otherwise false.
public void setChecked(boolean status) Changes the state of the CheckBox.

Android CheckBox Example

activity_main.xml

Drag the three checkboxes and one button for the layout. Now the activity_main.xml file will look like this:

File: activity_main.xml

Activity class

Write the code to check which toggle button is ON/OFF.

File: MainActivity.java

Output:

Android CheckBox

Email this to someonePrint this pageShare on Google+0Share on Facebook6Tweet about this on TwitterShare on LinkedIn0Share on Reddit0Pin on Pinterest0Share on StumbleUpon1

About Team

Browse Archived Articles by Team