LoginSignup
1
1

More than 5 years have passed since last update.

【Android】Kotlinで選択されたRadioGroupのインデックスを取得する

Posted at

やり方

  1. checkedRadioButtonIdでチェックされているRadioButtonのID取得
  2. 1のIDからRadioButton取得
  3. 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

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1