| |
screen类有四个子类: alert list textbox form
list根据choice接口的定义,分为:choice.exclusive(单选)choice.multiple(多选)choice.implicit(简易式的单选)
单选型image img=image.createimage("/a.png");list l=new list("list test",choice.exclusive);l.append("banana",img);l.append("apple",null);display.setcurrent(l);
insert()可在特定项目后插入一个新项目。set()可以重新设定某个项目。……system.out.println("you have choice the"+l.getselectedindex()+"item.");system.out.println("the content is:"+l.getstring(l.getselectedindex()));
多选型list l=new list("list test",choice.multiple);……int size=l.size();for (int i=0;i<=size;i++){ if(l.isselected(i)) { system.out.println("you have selected"+i); }}
getselectedflags()传回一个boolean数组,借此可了解那个选项被选中。
简易式单选list l=new list("list test",choice.implicit);……public void commandaction(command c,displayable s){if(c==list.select_command){list tmp=(list)s;int i=tmp.getselectedindex();system.out.println("you have selected"+i)}……}
choice.implicit在用户选择后,立刻引发事件,并将list.select_command通过commandaction()的第一个参数c传入。如果不希望这样,可以setselectcommand(null)将它关掉,此时c=null.setselectcommand(x)--x为另外一个command对象,当list被选中后,x作为commandaction()的第一个参数传入。
setselectcommand()后,这个command--x会被addcommand()自动加到系统菜单。removecommand(c)如同:setselectcommand(null);removecommand(c);
choice接口提供的fitpolicy机制,决定当文字内容过长时,该如何处理choice.text_wrap_on-过长的文字自动换行choice.text_wrap_off-过长的文字自动被截断choice.text_wrap_default-依照及其不同而不同,通常是前两种的一种
|
|