CheckBox Widget

he checkbox is a specific two-states button that can either be checked or unchecked. It is a widget and a subclass of CompoundButton class.

Available constructors for this class are the following:

public CheckBox (Context context)
public CheckBox (Context context, AttributeSet attrs)
public CheckBox (Context context, AttributeSet attrs, int defStyle)

Public methos are the following:

void  onInitializeAccessibilityEvent(AccessibilityEvent event)
Initializes an AccessibilityEvent with information about this View which is the event source.

void  onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info)
Initializes an AccessibilityNodeInfo with information about this view.

 

Below is a simple sample program for the checkbox.

Step 1:

Create an Android project named HelloCheckBox. The project structure will look like this:

Step 2:

Edit or create the layout view so that it will display the CheckBox widget.

 

Step 3:

Modify the Java source code so that it will handle the event when the checkbox object is clicked. We add the click listener so that it will display a message when the checkbox is clicked.

Below are the imported classes:

import android.os.Bundle;

import android.app.Activity;

import android.view.Menu;

import android.view.View;

import android.widget.CheckBox;

 

import android.widget.Toast;

Step 4:

Run the program. Try checking or unchecking on the checkbox object and see the message that will be displayed.

 

Be the first to comment

Leave a Reply

Your email address will not be published.


*