Anko RadioGroup

It’s hard to explain sometimes as much as to understand, in Android when you are calling a function you don’t know exactly what you are doing, what the supers an other artefacts will do…

The case I present is very simple an anko view/component that has a label and a radio group, everything goes smooth, so if I flip the screen the values are preserved automatically with no save bundles or parcerices …

Now unfortunately I need two radio groups and two labels (kind of settings), and then everything becomes a mess, the second radio group seems to take command over the first, so when I flip the screen both radio groups shows what the second showed before the flip

I did naively from the beginning assign radio groups to variables.

Then I started to fight furiously with the SaveInstanceState
and well all I could discover is that the bundle containing the set of preserved values contained just a set or radio buttons instead of two I’ve got the strong filing that this is the source of problem.

I’ve tried to implement a solution with the saveInstance but no way the second radio group always set his values to the first …

Thank you so much.

  class SelectLangView : AnkoComponent<SelectLangActivity> {
      var languageITeach     = 3
      var languageMyStudents = 3


  override fun createView(ui: AnkoContext<SelectLangActivity>)= with(ui) {    
      var ll=resources.getStringArray(R.array.languages)
      verticalLayout{
          lparams(width= matchParent,height = matchParent)
          textView{
              hint="Language to Teach"
              textSize=25f
         }.lparams(){margin=dip(10)}

        val rgLangToTeach=radioGroup {
            var n=0
            ll.forEach {
                radioButton {
                    id=n
                    text = it.toString()
                    if (id==languageITeach){
                          setChecked(true)                        
                    }
                    onClick {
                         languageITeach=id
                    }
                }.lparams(){leftPadding=dip(20)}
                n++
            }
        }

        textView{
            hint="Language of my students"
            textSize=25f
        }.lparams(){margin=dip(10)}

       val rgLangStudents=radioGroup {
            var n=0
            ll.forEach {
                radioButton {
                    id=n
                    text = it.toString()
                    if (id==languageMyStudents){
                        setChecked(true)
                    }
                   onClick {
                        languageMyStudents=id
                    }
                }.lparams(){leftPadding=dip(20)}
                n++
            }
        }

        linearLayout(){
            this.gravity=Gravity.CENTER_HORIZONTAL
            button("OK"){
                onClick {
                    val i=rgLangToTeach.checkedRadioButtonId
                    val j=rgLangStudents.checkedRadioButtonId
                    ctx.toast("LangToTeach:$i  LangStudents:$j ")

                }
            }.lparams(){margin=dip(25)}
           
        }
    }

  }
}

Well find out that just not allowing radiobutons have the same id everything goes as expected.
But I still think that there’s something wrong in the issue, because when the id’s are equal as they belong to another view everything goes fine except saving values …