Skip to content

Instantly share code, notes, and snippets.

@chelseatroy
Created May 20, 2020 05:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chelseatroy/aeea621dbc19f6b1fa742ff50c35e1ff to your computer and use it in GitHub Desktop.
Save chelseatroy/aeea621dbc19f6b1fa742ff50c35e1ff to your computer and use it in GitHub Desktop.
Exclusive Selection View Collection
...
var moods = arrayListOf<String>(
"UNSELECTED",
"UNSELECTED",
"UNSELECTED",
"UNSELECTED",
"UNSELECTED"
)
for ((index, button) in moodButtonCollection.withIndex()) {
val thisButtonIndex = index
button?.setOnClickListener({ view ->
for ((index, button) in moodButtonCollection.withIndex()) {
moods.set(thisButtonIndex, "SELECTED")
view.setBackgroundColor(selectedColor);
currentMood = Mood.values()[thisButtonIndex]
if (moods.get(index) == "SELECTED" && index != thisButtonIndex) {
moods.set(index, "UNSELECTED")
button?.setBackgroundColor(unselectedColor)
}
};
})
}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment