Creating a radio button
In Modern Android Development, RadioButton
is used similarly to how it is used in traditional Android development. RadioButton
allows users to select a single item from a list of mutually exclusive options, meaning only one option can be selected at a time.
In Jetpack Compose, RadioButton
is part of the Material Design library and can be used by importing the Androidx.compose.Material.RadioButton
package. To create a group of RadioButton
instances, you would typically use the RadioGroup
composable, which is also part of the Material Design library.
The RadioGroup
composable takes a list of options as input, along with a selected option and a callback that is called when the selected option changes. The individual RadioButton
instances can be created using the RadioButton
composable and added as children of RadioGroup
.
Getting ready
In this recipe, we will continue using the same project, so ensure you have completed previous recipes.