Java J2ME中的Onclick事件
我是J2ME编程新手。我需要选择组问题的点击事件 我有一个选择组问题来选择性别,无论是男性还是女性 如果我们选择男性,我需要以同样的形式生成新的选择问题 请为选项组问题的“点击”事件共享一些代码。在“midlet”中定义以下变量:Java J2ME中的Onclick事件,java,java-me,Java,Java Me,我是J2ME编程新手。我需要选择组问题的点击事件 我有一个选择组问题来选择性别,无论是男性还是女性 如果我们选择男性,我需要以同样的形式生成新的选择问题 请为选项组问题的“点击”事件共享一些代码。在“midlet”中定义以下变量: private Form frm = null; private Command cmdSelect = null; 在您的“midlet constractor”中超过此值: 在midlet类中附加此方法: private Form getForm() {
private Form frm = null;
private Command cmdSelect = null;
在您的“midlet constractor”中超过此值:
在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();
把你累了的代码放进去
int index = ((ChoiceGroup)this.frm.get(0)).getSelectedIndex();