Skip to main content

buttongroup failing

7 replies [Last post]
Anonymous

Hi,

I'm creating a form with radio buttons on it using this code:

for(int i = 0;i

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
francisdb
Offline
Joined: 2006-06-16

repost for the forums (crosspost was broken)

Hi,

I'm creating a form with radio buttons on it using this code:

for(int i = 0;i String url = urls[i];
RadioButton radioButton = new RadioButton(url);
radioButton.addActionListener(this);
buttonGroup.add(radioButton);
if(url != null && url.equals(curentUrl)){
buttonGroup.setSelected(radioButton);
}
this.addComponent(radioButton);
}

but this doesn't seem to work correctly, the button that is selected
upfront is not getting unselected when choosing an other one. Only
after selecting it and then choosing an other option will it be
unselected.

In what order should I do the following?

- add radio to form
- add radio to button group
- set radio selected

and how should I set a radio selected? using the group (like above) or
using the button itself?

francisdb
Offline
Joined: 2006-06-16

hmm square brackets not allowed?

Hi,

I'm creating a form with radio buttons on it using this code:

for(int i = 0;i String url = urls{i};
RadioButton radioButton = new RadioButton(url);
radioButton.addActionListener(this);
buttonGroup.add(radioButton);
if(url != null && url.equals(curentUrl)){
buttonGroup.setSelected(radioButton);
}
this.addComponent(radioButton);
}

but this doesn't seem to work correctly, the button that is selected
upfront is not getting unselected when choosing an other one. Only
after selecting it and then choosing an other option will it be
unselected.

In what order should I do the following?

- add radio to form
- add radio to button group
- set radio selected

and how should I set a radio selected? using the group (like above) or
using the button itself?

vprise
Offline
Joined: 2003-11-07

Hi Francisdb,
if I understand correctly you expect the radio button to change on focus?
This isn't the behavior of LWUIT which will only shift focus on selection, you can build a focus listener to change this behavior but we don't recommend it. It seems that what you want is a list not radio buttons (you can use a list with a radio button renderer see the LWUIT demo renderer sample).

Thanks,
Shai.

francisdb
Offline
Joined: 2006-06-16

Hehe, selected vs selected...

by selected I want to say the radio button that is currently 'checked', this has nothing to do with focus handling... (the methos setSelected() in RadioButton )
If I 'check' a button by default that radio button is not 'unchecked' when the user 'checks' a different radio button form the group.

Do I understand correctly that you have to add radio buttons to a group so that only one of them can be selected?

vprise
Offline
Joined: 2003-11-07

Hi Francisdb,
sorry I misunderstood you. The selection should work as you built it which is why I'm surprised it isn't working for you. You understood correctly that you should add to the button group and while we normally use radiobutton.setSelected() the other way around should be just as good.
I just tried your code and it seems to work correctly so I'm not exactly sure where the problem is?

Thanks,
Shai.

francisdb
Offline
Joined: 2006-06-16

There's not much more in my form than the code I submitted, a back command and a actionPerformed that saves the selected item text to rms.

Just to be sure you understand me: the initial selection is ok, but after focusing on an other item and 'clicking' it I have two items from the group selected. Have there been any bug fixes on those components since the 2nd binary drop?

vprise
Offline
Joined: 2003-11-07

> Just to be sure you understand me: the initial
> selection is ok, but after focusing on an other item
> and 'clicking' it I have two items from the group
> selected. Have there been any bug fixes on those
> components since the 2nd binary drop?

Yes, I understand and I don't see this problem. I don't think something significant changed here though... This code works for me:

Form test = new Form("Radio");
String[] urls = new String[] {"AAAA", "bbbb", "CCCCC", "DDDD"};
String curentUrl = "AAAA";
ButtonGroup buttonGroup = new ButtonGroup();
for(int i = 0;i String url = urls[i];
RadioButton radioButton = new RadioButton(url);
//radioButton.addActionListener(this);
buttonGroup.add(radioButton);
if(url != null && url.equals(curentUrl)){
buttonGroup.setSelected(radioButton);
}
test.addComponent(radioButton);
}
test.show();