Problems with Radio Toggle Buttons please Help


#1

I’m trying to use radio toggle buttons. i’ve created an array of toggle buttons set to the same radio ID very simular to the juice demo app. I’m adding each button in the array to the actionListnerList as they are created in the loop. for some reason the message string getting passed in the actionlistnerCallback function are not correct. Only some of the buttons name strings are being passed in and then its usualy not the correct string that corseponds to the button being pressed.

Can any one give me suggestions or have sample code i can look at on how to properly use radio buttons inside a companet?

Thanks


#2

what do you mean by “adding each button in the array to the actionListnerList”? Why do you need to add the buttons to this list?

Can you maybe post a fragment of your code here so we can see what the problem is?


#3

Thanks for the quick reply. when i say add to the ActionlistenerList i mean adding an actionlistener for each button in the array of toggle buttons. like
"Button[i]->addActionListener(this); " i assume this is the only way i can get a callback to the app so that i can assign a different function call to each button.

after doing some debugging it seams that the ActionListenerCallback function gets called twice onces for the button a just pressed and again for the button that was turned off in the same radio ID group which causes a big mess.

is there a better way to assign a action (ie function call) to each button in a radio group then useing actionListeners?


#4

I think this is how it should be, its not a mess, one button was turned on and another turned off…

if you don’t want a lot of if() in your code you can do the following

call setName() for each button and put there a string containing the button index in your array (setName is sent in the action if set instead of button text). You can also have names like “button1”, “button2” if you have callbacks from other widgets also

then you have one place in your code where you get callback with the button number, look using the array for the button and see if its on or off. now just ignore the off button and handle the on button…

I didn’t try it myself, just an idea :idea:


#5

Cool got it working correctly thanks a bunch


#6