문제

We are trying to create an application using the LWUIT Resource Editor as much as possible, it's to say, avoiding creating the UI by code if we can.

We found out there is the possibility to assign a group to a RadioButton by setting the corresponding property on the Resource Editor tool.

So, as we need to implement some functionality for those radio buttons, how can we get the reference to that ButtonGroup instance that the UIBuilder has created (I suppose)?

And yes, considering we are using the Resource Editor tool to generate our midlets, the "custom" code is written on the StateMachine class.

Regards.

도움이 되었습니까?

해결책

AFAIK you can't get ButtonGroup from ResourceEdit#GUI. You can only possible to get RadioButton group name. But possible to add the RadioButton into ButtonGroup through your code. See the following code,

For calling StateMachine() constructor(use this code inside of constructor),

Form form = (Form) this.startApp(resources, null, true);
 RadioButton rb1 = this.findRadioButton(form);
 RadioButton rb = this.findRadioButton1(form);
 ButtonGroup bg = new ButtonGroup();
 bg.add(rb);
 bg.add(rb1);
 bg.setSelected(0);

For calling StateMachine(String resFile) constructor(use this code inside of your MIDlet class),

 StateMachine sm = new StateMachine("/Sample.res");
 RadioButton rb1 = sm.findRadioButton(Display.getInstance().getCurrent());
 RadioButton rb = sm.findRadioButton1(Display.getInstance().getCurrent());
 ButtonGroup bg = new ButtonGroup();
 bg.add(rb);
 bg.add(rb1);
 bg.setSelected(0);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top