mohammed_sajid
mohammed_sajid

Reputation: 455

Kotlin check if any CheckBox isChecked

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)}}

Upvotes: 0

Views: 1157

Answers (1)

Dženan Bećirović
Dženan Bećirović

Reputation: 51

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

Upvotes: 1

Related Questions