Skip to main content

Simple example of using RadioGroup, RadioButton in Kotlin | Android

Here is the simple example of using RadioGroup, RadioButton in Android Kotlin.

  
<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/radioGroup"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.guna.kotlinapplication.BlankFragment">

    <RadioButton
        android:id="@+id/radioMale"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/male" />

    <RadioButton
        android:id="@+id/radioFemale"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/female" />
</RadioGroup>

OnCheckedChangeListener
  
radioGroup.setOnCheckedChangeListener({ group, checkedId ->
    val radioButton = view.findViewById<RadioButton>(checkedId)
    Toast.makeText(activity, radioButton.text.toString() + " is checked", Toast.LENGTH_LONG).show()
})


Here is the full video tutorial


Interesting right?


If you are really interested in this code, then please share this post with your friends.


Text WhatsApp message to +91-99654 70689 To join Android Developers WhatsApp group.
Join WhatsApp group by this link
Thank You


Comments