J2ME List_Multiple 多选模式

import javax.microedition.lcdui.Choice;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.List;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

//列表多选模式测试 MULTIPLE 案例:
public class List_Multiple_test extends MIDlet implements CommandListener{

//默认属性 定义
private final static Command CMD_EXIT = new Command("exit",Command.EXIT,1);
private final static Command CMD_BACK = new Command("BACK",Command.BACK,1);
private Display display;
private List mainList;
private List exclusiveList;
private List implicitList;
private List multipleList;
private boolean firstTime;

//编写构造方法
public List_Multiple_test(){
//获取对象
display = Display.getDisplay(this);

//初始化数组 ,Choice 文字选项部分
String[] stringArray = {
"Option A",
"Option B",
"Option C",
"Option D",
};

//Image[] 数组初始化
Image[] imageArray = null;

//exclusiveList 声明
exclusiveList = new List("ExclusiveList",Choice.EXCLUSIVE,stringArray,imageArray);
exclusiveList.addCommand(CMD_BACK);
exclusiveList.addCommand(CMD_EXIT);
exclusiveList.setCommandListener(this);

//implicitList 的声明,隐含模式
implicitList = new List("ImplicitList",Choice.IMPLICIT,stringArray,imageArray);
implicitList.addCommand(CMD_BACK);
implicitList.addCommand(CMD_EXIT);
implicitList.setCommandListener(this);

//multipleList 声明 多选模式
multipleList = new List("Multiple",Choice.MULTIPLE,stringArray,imageArray);
multipleList.addCommand(CMD_BACK);
multipleList.addCommand(CMD_EXIT);
multipleList.setCommandListener(this);

firstTime = true;
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub

}

protected void pauseApp() {
// TODO Auto-generated method stub

}

protected void startApp() throws MIDletStateChangeException {
// TODO Auto-generated method stub
if(firstTime){
Image[] imageArray = null;
try{
Image icon = Image.createImage("/images/eclipse.png");// 路径为相对路径
imageArray = new Image[]{icon,icon,icon};
}catch(Exception ex){
ex.printStackTrace();
}

String[] stringArray = {"Exclusive","Implicit","Multiple"};
mainList = new List("Choose Type",Choice.IMPLICIT,stringArray,imageArray);
mainList.addCommand(CMD_BACK);
mainList.addCommand(CMD_EXIT);
mainList.setCommandListener(this);
display.setCurrent(mainList);
firstTime = false;
}
}

public void commandAction(Command c, Displayable d) {
// TODO Auto-generated method stub
if(d.equals(mainList)){
//使用了隐含模式 , 选择的时候会以SELECT_COMMAND 作为第一参数传入
if(c==List.SELECT_COMMAND){
switch (((List)d).getSelectedIndex()) {
case 0:
display.setCurrent(exclusiveList);
break;
case 1:
display.setCurrent(implicitList);
break;
case 2:
display.setCurrent(multipleList);
break;
}
}else{
if(c==CMD_BACK){
display.setCurrent(mainList);
}
}
if(c==CMD_EXIT){
try {
destroyApp(false);
} catch (MIDletStateChangeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
notifyDestroyed();
}
}
}

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值