やり方
-
checkedRadioButtonId
でチェックされているRadioButtonのID取得 - 1のIDからRadioButton取得
-
indexOfChild
の引数に2のRadioButtonを指定してインデックス取得
サンプルコード
val radioGroup: RadioGroup = findViewById(R.id.radioGroup)
val id = radioGroup.checkedRadioButtonId
val radioButton = radioGroup.findViewById<RadioButton>(id)
val index = radioGroup.indexOfChild(radioButton)
参考
RadioGroup | Android Developers
https://developer.android.com/reference/android/widget/RadioGroup.html
java - How to get the selected index of a RadioGroup in Android - Stack Overflow
https://stackoverflow.com/questions/6440259/how-to-get-the-selected-index-of-a-radiogroup-in-android