2013-10-22 46 views
0

我是J2ME編程的新手。我需要選擇組問題上的點擊事件。J2ME中的Onclick事件

我有一個選擇組的問題,選擇男性或女性的性別。

如果我們選擇男性,我需要以相同的形式生成新的選擇題。

請分享一些代碼爲「點擊」事件選擇組問題。在你的 「的MIDlet constractor」

private Form frm = null; 
private Command cmdSelect = null; 

過去的這個:在你的MIDlet類

this.frm = this.getForm(); 
Display.getDisplay(this).setCurrent(this.frm); 

追加此方法:

+0

把你的代碼你累了 – Engineer

回答

0
你 「的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();