Checkbox control in Android Application

Checkbox control in Android Application

In this article I am going to explain how to create a checkbox control in android application by using CheckBox widget. When the CheckBox is pressed, toast message will indicate the current state of the checkbox and the text of the checkbox will change.

This captures the CheckBox element from the layout, and then adds a View.OnClickListener. The View.OnClickListener must implement the onClick(View) callback method, which defines the action to be made when the checkbox is clicked. When clicked, isChecked() is called to check the new state of the check box. If it has been checked, then a Toast displays the message "Selected" and change the checkbox text to "Unchecked me”, otherwise it displays "Not selected" and change the checkbox text to "Checked me".

· Run an application Your output is something like this:

When you checked the checkbox, a toast display a message "Selected" and checkbox text will change into "Unchecked me".

Again, when you unchecked the checkbox, a toast display a message "NotSelected" and checkbox text will change into "Checked me".