CheckBox belongs to android.widget.CheckBox class. Android CheckBox class is the subclass of CompoundButton class. It is generally used in a place where user can select one or more than choices from a given list of choices. For example, selecting hobbies.
public class CheckBox extends CompoundButton
Class Hierarchy :
java.lang.Object ↳ android.view.View ↳ android.widget.TextView ↳ android.widget.Button ↳ android.widget.CompoundButton ↳ android.widget.CheckBox
It has two states – checked or unchecked.
Methods of CheckBox class
- public boolean isChecked(): If CheckBox is in checked state then return true otherwise false.
- public void setChecked(boolean status): It changes the state of the CheckBox.
Below is the code for an example where the user chooses its hobbies from the given list containing Painting, Reading, Singing and Cooking with the help of CheckBox.
The activity_main.xml has a TextView, 4 CheckBoxes and a button.The TextView prompts the user to select his/her hobbies.
First user select its choices and then presses the Submit button. After pressing Submit button, a toast will generate showing the selected hobbies.
- Android | How to Request permissions in Android Application?
- Android | AdMob Banner Ads for Android Studio
- Android | How to add Radio Buttons in an Android Application?
- Android | Android Application File Structure
- Android | AdMob Interstitial Ads for Android Studio
- Android | Starting with first app/android project
- Android | Running your first Android app
- JavaFX | Checkbox
- Android | App to Add Two Numbers
- How to use WebView in Android
- Android | RecyclerView
- Android | 8.0 Oreo
- Android Boot Process
- Android | What is Toast and How to use it with Examples
- Android | Creating a SeekBar
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.