我是J2ME编程的新手。我需要在选择组问题上点击事件。
我有一个选择组问题来选择性别,男性或女性。
如果我们选择男性,我需要以相同的形式生成新的选择题。
请分享一些"On Click“事件的代码,用于选择组问题。
发布于 2013-10-22 16:37:20
在你的"midlet“中定义这个变量:
private Form frm = null;
private Command cmdSelect = null;在你的"midlet构造器“中:
this.frm = this.getForm();
Display.getDisplay(this).setCurrent(this.frm);将此方法附加到您的midlet类中:
private Form getForm()
{
Form form = new Form("test");
ChoiceGroup choice = new ChoiceGroup(null, ChoiceGroup.EXCLUSIVE);
choice.append("Male", null);
choice.append("Female", null);
form.append(choice);
this.cmdSelect = new Command("Select", Command.OK, 1);
form.addCommand(this.cmdSelect);
form.setCommandListener(this);
return form;
}并将此代码粘贴到commandAction方法中,以获取所选的索引:
int index = ((ChoiceGroup)this.frm.get(0)).getSelectedIndex(); https://stackoverflow.com/questions/19512470
复制相似问题