I have a stop button that turns all my checkboxes red.
When I select a checkbox it will turn blue, and when I uncheck it it will turn black.
I want my checkboxes to turn to red when their previous color was red and I want my checkboxes to turn black when their previous color was black.
This is the code I have right now to change the colors.
Change checked color
for (checkBox in checBoxes)
{
checkBox.setOnClickListener(View.OnClickListener {
if (checkBox.isChecked) {
checkBox.setBackgroundResource(R.drawable.blue_button)
} else {
checkBox.setBackgroundResource(R.drawable.black_button)
}
})
}
Stop button
stopBtn.setOnClickListener {
for (checkBox in checBoxes)
{
checkBox.setBackgroundResource(R.drawable.red_button)
}
}
2
Answers
This is my updated code @dženan-bećirović
Stop button
Change checked color
You can create boolean that will tell if user have clicked stop button like this:
Than make your onClickListener lambda function like this:
And then: