Added in API level 1

RadioGroup


open class RadioGroup : LinearLayout
kotlin.Any
   ↳ android.view.View
   ↳ android.view.ViewGroup
   ↳ android.widget.LinearLayout
   ↳ android.widget.RadioGroup

This class is used to create a multiple-exclusion scope for a set of radio buttons. Checking one radio button that belongs to a radio group unchecks any previously checked radio button within the same group.

Intially, all of the radio buttons are unchecked. While it is not possible to uncheck a particular radio button, the radio group can be cleared to remove the checked state.

The selection is identified by the unique id of the radio button as defined in the XML layout file.

XML Attributes

See RadioGroup Attributes, LinearLayout Attributes, ViewGroup Attributes, View Attributes

Also see LinearLayout.LayoutParams for layout attributes.

Summary

Nested classes
open

This set of layout parameters defaults the width and the height of the children to WRAP_CONTENT when they are not specified in the XML file.

abstract

Interface definition for a callback to be invoked when the checked radio button changed in this group.

Inherited XML attributes
Inherited constants
Public constructors
RadioGroup(context: Context!)

RadioGroup(context: Context!, attrs: AttributeSet!)

Public methods
open Unit
addView(child: View!, index: Int, params: ViewGroup.LayoutParams!)

open Unit

open Unit
check(id: Int)

Sets the selection to the radio button whose identifier is passed in parameter.

open Unit

Clears the selection.

open RadioGroup.LayoutParams!

Returns a new set of layout parameters based on the supplied attributes set.

open CharSequence!

open Int

Describes the autofill type of this view, so an android.service.autofill.AutofillService can create the proper AutofillValue when autofilling the view.

open AutofillValue?

open Int

Returns the identifier of the selected radio button in this group.

open Unit

open Unit

Register a callback to be invoked when the checked radio button changes in this group.

open Unit

Register a callback to be invoked when a child is added to or removed from this view.

Protected methods
open Boolean

open LinearLayout.LayoutParams!

open Unit

Finalize inflating a view from XML.

Inherited functions
Inherited properties

Public constructors

RadioGroup

Added in API level 1
RadioGroup(context: Context!)

RadioGroup

Added in API level 1
RadioGroup(
    context: Context!,
    attrs: AttributeSet!)

Public methods

addView

Added in API level 1
open fun addView(
    child: View!,
    index: Int,
    params: ViewGroup.LayoutParams!
): Unit
Parameters
child View!: the child view to add
index Int: the position at which to add the child or -1 to add last
params ViewGroup.LayoutParams!: the layout parameters to set on the child

autofill

Added in API level 26
open fun autofill(value: AutofillValue!): Unit
Parameters
value AutofillValue!: value to be autofilled.

check

Added in API level 1
open fun check(id: Int): Unit

Sets the selection to the radio button whose identifier is passed in parameter. Using -1 as the selection identifier clears the selection; such an operation is equivalent to invoking clearCheck().

Parameters
id Int: the unique id of the radio button to select in this group

clearCheck

Added in API level 1
open fun clearCheck(): Unit

Clears the selection. When the selection is cleared, no radio button in this group is selected and getCheckedRadioButtonId() returns null.

generateLayoutParams

Added in API level 1
open fun generateLayoutParams(attrs: AttributeSet!): RadioGroup.LayoutParams!

Returns a new set of layout parameters based on the supplied attributes set.

Parameters
attrs AttributeSet!: the attributes to build the layout parameters from
Return
RadioGroup.LayoutParams! an instance of android.view.ViewGroup.LayoutParams or one of its descendants

getAccessibilityClassName

Added in API level 23
open fun getAccessibilityClassName(): CharSequence!

getAutofillType

Added in API level 26
open fun getAutofillType(): Int

Describes the autofill type of this view, so an android.service.autofill.AutofillService can create the proper AutofillValue when autofilling the view.

By default returns AUTOFILL_TYPE_NONE, but views should override it to properly support the Autofill Framework.

Return
Int Value is android.view.View#AUTOFILL_TYPE_NONE, android.view.View#AUTOFILL_TYPE_TEXT, android.view.View#AUTOFILL_TYPE_TOGGLE, android.view.View#AUTOFILL_TYPE_LIST, or android.view.View#AUTOFILL_TYPE_DATE

getAutofillValue

Added in API level 26
open fun getAutofillValue(): AutofillValue?

getCheckedRadioButtonId

Added in API level 1
open fun getCheckedRadioButtonId(): Int

Returns the identifier of the selected radio button in this group. Upon empty selection, the returned value is -1.

Return
Int the unique id of the selected radio button in this group

onInitializeAccessibilityNodeInfo

Added in API level 14
open fun onInitializeAccessibilityNodeInfo(info: AccessibilityNodeInfo!): Unit
Parameters
info AccessibilityNodeInfo!: The instance to initialize.

setOnCheckedChangeListener

Added in API level 1
open fun setOnCheckedChangeListener(listener: RadioGroup.OnCheckedChangeListener!): Unit

Register a callback to be invoked when the checked radio button changes in this group.

Parameters
listener RadioGroup.OnCheckedChangeListener!: the callback to call on checked state change

setOnHierarchyChangeListener

Added in API level 1
open fun setOnHierarchyChangeListener(listener: ViewGroup.OnHierarchyChangeListener!): Unit

Register a callback to be invoked when a child is added to or removed from this view.

Parameters
listener ViewGroup.OnHierarchyChangeListener!: the callback to invoke on hierarchy change

Protected methods

checkLayoutParams

Added in API level 1
protected open fun checkLayoutParams(p: ViewGroup.LayoutParams!): Boolean

generateDefaultLayoutParams

Added in API level 1
protected open fun generateDefaultLayoutParams(): LinearLayout.LayoutParams!
Return
LinearLayout.LayoutParams! a set of default layout parameters or null

onFinishInflate

Added in API level 1
protected open fun onFinishInflate(): Unit

Finalize inflating a view from XML. This is called as the last phase of inflation, after all child views have been added.

Even if the subclass overrides onFinishInflate, they should always be sure to call the super method, so that we get called.
If you override this method you must call through to the superclass implementation.