import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.ChoiceGroup;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.ItemStateListener;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class ChoiceGroupMIDlet extends MIDlet implements ItemStateListener {
private Display display;
private Form form;
//零或多选模式
ChoiceGroup choice=new ChoiceGroup("薪酬",ChoiceGroup.MULTIPLE);
//POPUP弹出菜单模式
//ChoiceGroup choice=new ChoiceGroup("薪酬",ChoiceGroup.POPUP);
//ChoiceGroup.IMPLICIT专业与list类的实例中
public ChoiceGroupMIDlet () {
display = Display.getDisplay(this);
form=new Form("");
choice.append("600以下",null);
choice.append("600~1000",null);
choice.append("1000~3000",null);
choice.append("3000~5000",null);
choice.append("5000以上",null);
form.append(choice);
form.setItemStateListener(this);
}
protected void startApp() {
display.setCurrent(form) ;
}
protected void pauseApp() {
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
}
public void itemStateChanged(Item item){
String selStr="";
System.out.println(choice.size());
boolean[] strArray=new boolean[choice.size()];
choice.getSelectedFlags(strArray);
//测试状态数组中的数据
for(int i=0;i<strArray.length;i++){
System.out.println(strArray[i]);
}
//显示被选择的数据
for(int i=0;i<strArray.length;i++){
if (strArray[i]){
selStr=selStr+choice.getString(i)+";";
}
}
Alert alert=new Alert("提示",selStr+"被选中",null,null);
display.setCurrent(alert);
}
}