Android CheckBox - Androhub

CheckBox

Android CheckBox

A CheckBox is an on/off switch that can be toggled by the user. You should use check-boxes when presenting users with a group of selectable options that are not mutually exclusive.

CheckBox Attributes

Following are the important attributes related to CheckBox control. You can check Android official documentation for complete list of attributes and related methods which you can use to change these attributes are run time.

AttributeDescription
android:autoTextIf set, specifies that this TextView has a textual input method and automatically corrects some common spelling errors.
android:drawableBottomThis is the drawable to be drawn below the text.
android:drawableRightThis is the drawable to be drawn to the right of the text.
android:editableIf set, specifies that this TextView has an input method.
android:textThis is the Text to display.

Example

In this example i will be demonstrating how to control on CheckBox.

VIDEO DEMO

Let’s get start by creating a project in Eclipse IDE.

1. Create a new project in Eclipse by navigating to File ⇒ New Android ⇒ Application Project and fill required details. (I kept my main activity name as MainActivity.java)

2. Open your your AndroidManifest.xml file and make your “MainActivity” as Launcher activity, there is no change in this manifest file.

3. Create a layout file for MainActivtiy.java under res ⇒ layout folder. I named the layout file as activity_main.xml. In this layout there are two layout displaying two separated kind of checkbox.

4. Now, add the following code in MainActivity.java. In this class we displayed the selected checkbox name and it is checked or not via button click and check box clicking.

5. Run the application and you will get the output as shown in video and you are done.

Thanks. 🙂

 

Post comment

Your email address will not be published. Required fields are marked *