ButtonGroup and ResourceEditor
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 possib开发者_JS百科ility 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);
精彩评论