Skip to content

Instantly share code, notes, and snippets.

@johanneslagos
Last active January 25, 2019 14:53
Show Gist options
  • Save johanneslagos/c92133d657d0699192a110148c3407a4 to your computer and use it in GitHub Desktop.
Save johanneslagos/c92133d657d0699192a110148c3407a4 to your computer and use it in GitHub Desktop.
Old Fashioned toggle buttons.
override fun onCreateView(layoutInflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val toggle1 = view.toggle_button_1
val toggle2 = view.toggle_button_2
toggle1.setOnClickListener { onToggle(it) }
toggle2.setOnClickListener { onToggle(it) }
toggleGroup = view.toggle_group
toggleGroup.setOnCheckedChangeListener { group, checkedId ->
for (i in 0 until group.childCount) {
val button = group.getChildAt(i) as ToggleButton
button.isChecked = button.id == checkedId
}
}
}
private fun onToggle(view: View){
(view.parent as RadioGroup).check(view.id)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment