Behavior noticed when adding RadioButton and initial check at the same time in code

I was addicted to RadioGroup and RadioButton

This is the first post.

I noticed it while working at Kotlin, so I output it appropriately.

Premise

Behavior you want

"* I want to add the initial value of the Radio Button that will be added *"

Often.

code

list = listOf(1, 2, 3)//Meaningful information
radioGroup = findById(R.id.radio_group) as RadioGroup
for (data in list){
    val radioButton = RadioButton(this)
    if (data == 1){
        //I want to use it as an initial value!
        radioButton.isChecked = true
    }
    radioGroup.addView(radioButton)
}

Looks good

The purpose I saw is checked and very good

checkedRadioButtonId cannot be taken correctly

Refact

list = listOf(1, 2, 3)//Meaningful information
radioGroup = findById(R.id.radio_group) as RadioGroup
for (data in list){
    val radioButton = RadioButton(this)
    //Register RadioButton as SubView immediately after declaration
    radioGroup.addView(radioButton)
    if (data == 1){
        //I want to use it as an initial value!
        radioButton.isChecked = true
    }
}

moved

I did it.

Impressions

Recommended Posts

Behavior noticed when adding RadioButton and initial check at the same time in code
[Java] Method call error when inheritance and interface implementation are performed at the same time
Check the actual date and time at parse with Java's SimpleDateFormat
Launch webpack-dev-server and docker-compose at the same time on Windows Terminal and display them in another pane
Draw a bar graph and a line graph at the same time with MPAndroidChart
Check static and public behavior in Java methods
Check when created_at, datetime, etc. are not saved in Japan time in Docker and Rails
How to delete the tweet associated with the user when you delete it at the same time
[Spring Boot] POST file array / list and other data at the same time [Axios]
Check the behavior of getOne, findById, and query methods in Spring Boot + Spring Data JPA
Form and process file and String data at the same time with Spring Boot + Java
Differences in code when using the length system in Java
Implementation method of linking multiple images to one post and posting at the same time