In Android RadioGroup is used to set radio buttons. If one radio button is selected within the RadioGroup, all other ones are automatically deselected.
In this article we will be discussing how to programmatically create a RadioGroup in Kotlin .
Let’s start by first creating a project in Android Studio. To do so, follow these instructions:
- Click on File, then New and then New Project and give name whatever you like
- Then, select Kotlin language Support and click next button.
- Select minimum SDK, whatever you need
- Select Empty activity and then click finish.
After that, we need to design our layout. For that we need to work with the XML file. Go to app > res > layout and paste the folllowing code:
Modify activity_main.xml file
The next step is to code our RadioGroup. Open app/src/main/java/yourPackageName/MainActivity.kt and paste the following code:
The above code will still produce some errors because we have used some strings which have been declared in another file, to resolve these add the following code snippet to app/res/values/strings.xml
Run as Emulator:
- Dynamic TextSwitcher in Kotlin
- Dynamic ImageSwitcher in Kotlin
- Dynamic ProgressBar in Kotlin
- Dynamic Chronometer in Kotlin
- Dynamic ImageView in Kotlin
- Dynamic ScrollView in Kotlin
- Dynamic Button in Kotlin
- Dynamic TextView in Kotlin
- Dynamic Spinner in Kotlin
- Dynamic RatingBar in Kotlin
- Dynamic SeekBar in Kotlin
- Dynamic Switch in Kotlin
- Dynamic RadioButton in Kotlin
- Dynamic CheckedTextView in Kotlin
- Dynamic ImageButton in Kotlin
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.