Home > Back-end >  Kotlin check if any CheckBox isChecked
Kotlin check if any CheckBox isChecked

Time:02-21

Is there a simple way of making this? I have around 16 of these CheckBoxes.

 kartBox1.setOnClickListener{
            if(kartBox1.isChecked){kartBox1.setBackgroundResource(R.drawable.check_button_checked)}
            else{kartBox1.setBackgroundResource(R.drawable.check_button_unchecked)}}
    kartBox2.setOnClickListener{
            if(kartBox2.isChecked){kartBox2.setBackgroundResource(R.drawable.check_button_checked)}
            else{kartBox2.setBackgroundResource(R.drawable.check_button_unchecked)}}

CodePudding user response:

You can basically create list of those buttons and loop through it with foreach and add listeners with all needed checks.

  • Related