`
1140566087
  • 浏览: 548420 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
博客专栏
2c4ae07c-10c2-3bb0-a106-d91fe0a10f37
c/c++ 入门笔记
浏览量:18103
3161ba8d-c410-3ef9-871c-3e48524c5263
Android 学习笔记
浏览量:309777
Group-logo
J2ME 基础学习课程集
浏览量:18054
A98a97d4-eb03-3faf-af96-c7c28f709feb
Spring 学习过程记录...
浏览量:17217
社区版块
存档分类
最新评论

J2ME List_Multiple 多选模式

    博客分类:
  • J2ME
阅读更多
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();
			}
		}
	}

}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics