RadioButton


public class RadioButton
extends CompoundButton

java.lang.Object
   ↳ android.view.View
     ↳ android.widget.TextView
       ↳ android.widget.Button
         ↳ android.widget.CompoundButton
           ↳ android.widget.RadioButton


A radio button is a two-states button that can be either checked or unchecked. When the radio button is unchecked, the user can press or click it to check it. However, contrary to a CheckBox, a radio button cannot be unchecked by the user once checked.

Radio buttons are normally used together in a RadioGroup. When several radio buttons live inside a radio group, checking one radio button unchecks all the others.

See the Radio Buttons guide.

XML attributes

See CompoundButton Attributes, Button Attributes, TextView Attributes, View Attributes

Summary

Inherited XML attributes

Inherited constants

Inherited fields

Public constructors

RadioButton(Context context)
RadioButton(Context context, AttributeSet attrs)
RadioButton(Context context, AttributeSet attrs, int defStyleAttr)
RadioButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)

Public methods

CharSequence getAccessibilityClassName()

Return the class name of this object to be used for accessibility purposes.

void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info)

Initializes an AccessibilityNodeInfo with information about this view.

void toggle()

Change the checked state of the view to the inverse of its current state

If the radio button is already checked, this method will not toggle the radio button.

Inherited methods

Public constructors

RadioButton

Added in API level 1
public RadioButton (Context context)

Parameters
context Context

RadioButton

Added in API level 1
public RadioButton (Context context, 
                AttributeSet attrs)

Parameters
context Context

attrs AttributeSet

RadioButton

Added in API level 1
public RadioButton (Context context, 
                AttributeSet attrs, 
                int defStyleAttr)

Parameters
context Context

attrs AttributeSet

defStyleAttr int

RadioButton

Added in API level 21
public RadioButton (Context context, 
                AttributeSet attrs, 
                int defStyleAttr, 
                int defStyleRes)

Parameters
context Context

attrs AttributeSet

defStyleAttr int

defStyleRes int

Public methods

getAccessibilityClassName

Added in API level 23
public CharSequence getAccessibilityClassName ()

Return the class name of this object to be used for accessibility purposes. Subclasses should only override this if they are implementing something that should be seen as a completely new class of view when used by accessibility, unrelated to the class it is deriving from. This is used to fill in AccessibilityNodeInfo.setClassName.

Returns
CharSequence

onInitializeAccessibilityNodeInfo

Added in API level 14
public void onInitializeAccessibilityNodeInfo (AccessibilityNodeInfo info)

Initializes an AccessibilityNodeInfo with information about this view. The base implementation sets:

Subclasses should override this method, call the super implementation, and set additional attributes.

If an AccessibilityDelegate has been specified via calling setAccessibilityDelegate(android.view.View.AccessibilityDelegate) its AccessibilityDelegate#onInitializeAccessibilityNodeInfo(View, AccessibilityNodeInfo) is responsible for handling this call.


If you override this method you must call through to the superclass implementation.

Parameters
info AccessibilityNodeInfo: The instance to initialize.

toggle

Added in API level 1
public void toggle ()

Change the checked state of the view to the inverse of its current state

If the radio button is already checked, this method will not toggle the radio button.