| java.lang.Object | ||
| ↳ | com.neomades.ui.View | |
| ↳ | com.neomades.ui.CheckBox | |
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);
By default, the following properties are applied to a new CheckBox:
MATCH_PARENT.MATCH_CONTENT.LEFT|VCENTER.| 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
| |||||||||||
Constructs a default checkbox without text and unchecked state.
Constructs a default checkbox with the given text and unchecked
| text | the text of this check box |
|---|
Constructs a default checkbox with the given text and given checked state
| text | the text of this check box |
|---|---|
| checked | if the checkbox is checked |
Constructs a default checkbox with the text corresponding to the given string id and unchecked
| resId | the string id assigned to this check box |
|---|
Constructs a default checkbox with the text corresponding to the given string id and given checked state
| resId | the string id assigned to this check box |
|---|---|
| checked | if the checkbox is checked |
Returns the current text of the checkbox. Returns an empty string ("") if there is no text.
Return the checked state of the check box
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
| listener | Checkbox state change listener |
|---|
Check or uncheck the checkbox
| checked | new checked state of the check box : true to check, false to uncheck |
|---|
| CrossThreadException | if the method is called from outside the UI-Thread |
|---|
Sets the checkbox text font.
| font | new font for the text |
|---|
| CrossThreadException | if the method is called from outside the UI-Thread |
|---|---|
| NullPointerException | if the font parameter is null |
Sets the text of the checkbox
| text | The new text |
|---|
| CrossThreadException | if the method is called from outside the UI-Thread |
|---|
Sets the text of the checkbox
| resId | the string id assigned to this check box |
|---|
| CrossThreadException | if the method is called from outside the UI-Thread |
|---|
Sets the text color of this checkbox's text
| color | The color to set (with the alpha channel) |
|---|
| CrossThreadException | if the method is called from outside the UI-Thread |
|---|
Sets the text size to a given value (in dp).
| sizeInDp | size to set to the text |
|---|