public class

RadioButton

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

Class Overview

A RadioButton is a two states item (checked, unchecked). However, unlike CheckBox, items cannot be unselected by the user once checked. RadioButtons are normally used into RadioGroup. In that case, their state are linked and only one item can be checked at a time.

Note that a RadioButton is not necessarily part of a RadioGroup: it can be added directly to a layout.

Handling selection changes

Default properties

Cross Platform Considerations

In Android, a RadioButton is a android.widget.RadioButton. It is composed of an image, for which the visual aspect changes if the button is checked or unchecked, and a text at the right of the image.

In iOS, a RadioButton is a UITableViewCell inside a UITableViewController. A check mark is drawn at the right of the button text to indicate if the item is checked or not. The mark is inside the cell.

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
RadioButton()
Constructs a new RadioButton, with no text and unchecked.
RadioButton(String text)
Constructs a new RadioButton, with the given text and unchecked.
RadioButton(String text, boolean checked)
Constructs a new RadioButton, with the given text and the given checked state.
RadioButton(int resId)
Constructs a new RadioButton, with the given text and unchecked.
RadioButton(int resId, boolean checked)
Constructs a new RadioButton, with the given text and the given checked state.
Public Methods
RadioGroup getRadioGroup()
Returns the RadioGroup of the RadioButton ( null if the button has not yet been added to a group).
String getText()
Returns the current text of the radio button.
boolean isChecked()
Returns the current state of the RadioButton.
void setCheckChangedListener(CheckChangedListener listener)
Sets a listener that will listen for the state of the radio button (checked or unchecked).
void setChecked(boolean checked)
Sets the state of the RadioButton to checked or unchecked.
void setFont(Font font)
Sets the radio button text font.
void setText(String text)
Sets the text of this RadioButton.
void setText(int resId)
Sets the text of this RadioButton.
void setTextColor(Color color)
Sets the text color of this radio button'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 RadioButton ()

Constructs a new RadioButton, with no text and unchecked.

public RadioButton (String text)

Constructs a new RadioButton, with the given text and unchecked.

Parameters
text the radio button's text

public RadioButton (String text, boolean checked)

Constructs a new RadioButton, with the given text and the given checked state.

Parameters
text the radio button's text
checked the checked state

public RadioButton (int resId)

Constructs a new RadioButton, with the given text and unchecked.

Parameters
resId the string id assigned to this radio button text

public RadioButton (int resId, boolean checked)

Constructs a new RadioButton, with the given text and the given checked state.

Parameters
resId the string id assigned to this radio button text
checked the checked state

Public Methods

public RadioGroup getRadioGroup ()

Returns the RadioGroup of the RadioButton ( null if the button has not yet been added to a group).

Returns
  • the RadioGroup of this RadioButton or null if the button is not yet into a group

public String getText ()

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

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

public boolean isChecked ()

Returns the current state of the RadioButton.

Related XML Attributes
Returns
  • true if the button is checked, false otherwise

public void setCheckChangedListener (CheckChangedListener listener)

Sets a listener that will listen for the state of the radio button (checked or unchecked). When the state changes, onCheckChange(View, boolean) of the listener is called with the RadioButton and its new state as parameters.

Parameters
listener listener CheckChangedListener

public void setChecked (boolean checked)

Sets the state of the RadioButton to checked or unchecked.

Related XML Attributes
Parameters
checked new state of the RadioButton : true for checked, false for unchecked
Throws
CrossThreadException if the method is called from outside the UI-Thread

public void setFont (Font font)

Sets the radio button 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 this RadioButton.

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 this RadioButton.

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

public void setTextColor (Color color)

Sets the text color of this radio button'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