public class

CheckBox

extends View
java.lang.Object
   ↳ com.neomades.ui.View
     ↳ com.neomades.ui.CheckBox

Class Overview

A CheckBox represents a text with a check item into screen in order to intercept events (touch and keys) to set a binary state (checked/unchecked).

Handling Check changes

A typical use of CheckBox could be:

 CheckChangedListener checkboxListener = new CheckChangedListener() {
 	public void onCheckChange(View source, boolean checked) {
 		// do some stuff
 	}
 };
 CheckBox myCheckBox = new CheckBox("Text of the checkbox");
 myCheckBox.setCheckChangedListener(checkboxListener);
 layout.add(myCheckBox);
 

Default properties

By default, the following properties are applied to a new CheckBox:

  • focusable (limited to some devices)
  • clickable
  • enabled
  • no text
  • unchecked
  • width content stretch : MATCH_PARENT.
  • height content stretch : MATCH_CONTENT.
  • content alignment : LEFT|VCENTER.

Summary

XML Attributes
Attribute Name Related Method Description
checked setChecked(boolean) To check the checkbox  
font setFont(Font) Font resource id: Res.font.FONT_XXXX  
text setText(int) Res.string.XXXX or a text  
textColor setTextColor(Color) #AARRGGBB or a color  
textSize setTextSize(int) a size in dp  
[Expand]
Inherited XML Attributes
From class com.neomades.ui.View
[Expand]
Inherited Constants
From interface com.neomades.ui.Alignment
From interface com.neomades.ui.StretchMode
Public Constructors
CheckBox()
Constructs a default checkbox without text and unchecked state.
CheckBox(String text)
Constructs a default checkbox with the given text and unchecked
CheckBox(String text, boolean checked)
Constructs a default checkbox with the given text and given checked state
CheckBox(int resId)
Constructs a default checkbox with the text corresponding to the given string id and unchecked
CheckBox(int resId, boolean checked)
Constructs a default checkbox with the text corresponding to the given string id and given checked state
Public Methods
String getText()
Returns the current text of the checkbox.
boolean isChecked()
Return the checked state of the check box
void setCheckChangedListener(CheckChangedListener listener)
Sets a listener that will listen for the checked state of the checkbox When the checked state of the check box changes, the onCheckChange() method of the listener is called, by passing as a first argument the check box, and as a second argument a boolean indicating if the check box is checked or not
void setChecked(boolean checked)
Check or uncheck the checkbox
void setFont(Font font)
Sets the checkbox text font.
void setText(String text)
Sets the text of the checkbox
void setText(int resId)
Sets the text of the checkbox
void setTextColor(Color color)
Sets the text color of this checkbox's text
void setTextSize(int sizeInDp)
Sets the text size to a given value (in dp).
[Expand]
Inherited Methods
From class com.neomades.ui.View
From class java.lang.Object

XML Attributes

checked

To check the checkbox

Related Methods

font

Font resource id: Res.font.FONT_XXXX

Related Methods

text

Res.string.XXXX or a text

Related Methods

textColor

#AARRGGBB or a color

Related Methods

textSize

a size in dp

Related Methods

Public Constructors

public CheckBox ()

Constructs a default checkbox without text and unchecked state.

public CheckBox (String text)

Constructs a default checkbox with the given text and unchecked

Parameters
text the text of this check box

public CheckBox (String text, boolean checked)

Constructs a default checkbox with the given text and given checked state

Parameters
text the text of this check box
checked if the checkbox is checked

public CheckBox (int resId)

Constructs a default checkbox with the text corresponding to the given string id and unchecked

Parameters
resId the string id assigned to this check box

public CheckBox (int resId, boolean checked)

Constructs a default checkbox with the text corresponding to the given string id and given checked state

Parameters
resId the string id assigned to this check box
checked if the checkbox is checked

Public Methods

public String getText ()

Returns the current text of the checkbox. Returns an empty string ("") if there is no text.

Related XML Attributes
Returns
  • the current text of the checkbox. Returns an empty string ("") if there is no text.

public boolean isChecked ()

Return the checked state of the check box

Related XML Attributes
Returns
  • true if the check box is checked, else false

public void setCheckChangedListener (CheckChangedListener listener)

Sets a listener that will listen for the checked state of the checkbox When the checked state of the check box changes, the onCheckChange() method of the listener is called, by passing as a first argument the check box, and as a second argument a boolean indicating if the check box is checked or not

Parameters
listener Checkbox state change listener

public void setChecked (boolean checked)

Check or uncheck the checkbox

Related XML Attributes
Parameters
checked new checked state of the check box : true to check, false to uncheck
Throws
CrossThreadException if the method is called from outside the UI-Thread

public void setFont (Font font)

Sets the checkbox text font.

Related XML Attributes
Parameters
font new font for the text
Throws
CrossThreadException if the method is called from outside the UI-Thread
NullPointerException if the font parameter is null

public void setText (String text)

Sets the text of the checkbox

Related XML Attributes
Parameters
text The new text
Throws
CrossThreadException if the method is called from outside the UI-Thread

public void setText (int resId)

Sets the text of the checkbox

Related XML Attributes
Parameters
resId the string id assigned to this check box
Throws
CrossThreadException if the method is called from outside the UI-Thread

public void setTextColor (Color color)

Sets the text color of this checkbox's text

Related XML Attributes
Parameters
color The color to set (with the alpha channel)
Throws
CrossThreadException if the method is called from outside the UI-Thread

public void setTextSize (int sizeInDp)

Sets the text size to a given value (in dp).

Related XML Attributes
Parameters
sizeInDp size to set to the text