问题
Imaging e.g. 2 RadioButtons which share one ToggleGroup. Using
ToggleGroup.getToggles()
one can access all Toggles of the ToggleGroup. But is there any reference from a Toggle to the RadioButton that is linked to?
回答1:
If I understood the question correctly you're looking for:
RadioButton button = (RadioButton) toggleGroup.getSelectedToggle();
Unfortunatly, the ToggleGroup isn't "generified" yet, so you need the cast.
But is there any reference from a Toggle to the RadioButton that is linked to?
Or in other words: RadioButton is a (implements) Toggle, there isn't any reference.
来源:https://stackoverflow.com/questions/14885608/link-between-toggle-and-e-g-the-radiobutton-behind-it