📄 listtest.java
字号:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class ListTest extends MIDlet implements CommandListener{
Display display;
List imList,exList,muList;
Command exitCmd, backCmd;
public ListTest(){
imList = new List("选择一个List",List.IMPLICIT);
exList = new List("选择一个项目",List.EXCLUSIVE);
muList = new List("选择多个项目",List.MULTIPLE);
exitCmd = new Command("退出",Command.EXIT,1);
backCmd = new Command("返回",Command.BACK,1);
imList.append("EXCLUSIVE",null);
imList.append("MULTIPLE",null);
imList.setCommandListener(this);
imList.addCommand(exitCmd);
exList.append("项目1",null);
exList.append("项目2",null);
exList.append("项目3",null);
exList.setCommandListener(this);
exList.addCommand(exitCmd);
exList.addCommand(backCmd);
muList.append("项目1",null);
muList.append("项目2",null);
muList.append("项目3",null);
muList.setCommandListener(this);
muList.addCommand(backCmd);
muList.addCommand(exitCmd);
}
public void startApp(){
display = Display.getDisplay(this);
display.setCurrent(imList);
}
public void pauseApp(){
}
public void destroyApp(boolean unconditional){
}
public void commandAction(Command c, Displayable d){
if(c == List.SELECT_COMMAND){
switch(imList.getSelectedIndex()){
case 0:
display.setCurrent(exList);
break;
case 1:
display.setCurrent(muList);
break;
}
}
else if(c == backCmd){
List currentList = (List)display.getCurrent();
int size = currentList.size();
boolean[] selectedArray = new boolean[size];
currentList.getSelectedFlags(selectedArray);
for(int i=0;i<selectedArray.length;i++){
if(selectedArray[i]){
if(currentList == exList)
System.out.println("EXCLUSIVE:Item"+i+" is selected!");
else if(currentList == muList)
System.out.println("MULTIPLE:Item"+i+" is selected!");
}
}
display.setCurrent(imList);
}
else if(c == exitCmd){
destroyApp(false);
notifyDestroyed();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -