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.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Android | How to Create/Start a New Project in Android Studio?
- 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 | How to Request permissions in Android Application?
- Android | Running your first Android app
- Difference between Android 1.0 and Android 1.1
- JavaFX | Checkbox
- How to add ColorSeekBar in Android
- Android UI Layouts
- Android | RecyclerView
- Android | 8.0 Oreo
- Android SearchView with Example
- How to add ViewFlipper in android?
- How to Use Android on Windows 10?
- How to add a Snackbar in Android
- Android | App to Add Two Numbers
- How to use WebView in Android
- Android Menus
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.