Reputation: 57
How can someone retrieve the element that was put into a toggle group? Or perhaps there is another way to organize controls so they can be toggled and clients are also able get the actual control from within the group?
What I have
RadioButton radio1 = new RadioButton();
RadioButton radio12= new RadioButton();
ToggleGroup toggleGroup = new ToggleGroup();
radio1.setToggleGroup(toggleGroup);
radio2.setToggleGroup(toggleGroup);
What I want
RadioButton temp = toggleGroup.getSelectedObject();
Or
RadioButton temp = toggleGroup.getSelectedToggle().getObject();
Upvotes: 0
Views: 370
Reputation: 5032
If you want retrieve all toggle on the group:
toggleGroup.getToggles()
give you a list of all toggle.
if you want the selected toggle :
toggleGroup.getSelectedToggle()
give you a Toggle object.
So I think on this line RadioButton temp = toggleGroup.getSelectedObject();
you have to cast like that RadioButton temp =(RadioButton) toggleGroup.getSelectedObject();
Upvotes: 1