Last active
January 25, 2019 14:53
-
-
Save johanneslagos/c92133d657d0699192a110148c3407a4 to your computer and use it in GitHub Desktop.
Old Fashioned toggle buttons.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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