android checkbox example

CheckBox In Android :

Like radio buttons, checkboxes enable users to pick one or more choices from a list. A CheckBox has 2 states: checked or unchecked. not like radio buttons (radio button example), checkboxes will be checked and unchecked by the user while not regard to the state of different checkboxes. This example shows a way to use checkboxes in your android application.

Note : This example (Project) is developed in Eclipse Version Kepler, tested on Android 4.4.2 (KitKat Version) and SDK build-tools 22.6.3

Solution Stuff :

In this Android checkbox example, you can use “android.widget.CheckBox” class to render a checkbox.

You just need to drag and drop check box in Android UI (according below figure) and write some code for checkbox application:

android checkbox example

 

Complete Source code :

1. Put this code in main_activity.xml

The CheckBox component defines an item for users to check or uncheck. Android supports a special type of checkbox known as the star checkbox. You can display a star checkbox by setting the style attribute and setting its value to style=”?android:attr/starStyle”

2. Put this java code in MainActivity.class

To get the state of a checkbox, you need to listen to its onClick event. The isChecked() method of the checkbox returns true if the checkbox is checked, or false if it is not. Figure shows the Toast class displaying the state of the Autosave checkbox.

android checkbox example

Android CheckBox Example Source code Download :


Leave a Reply