《Java 手机/PDA 程序设计入门》读书笔记3--LCDAUI高级API之List

王朝java/jsp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

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-依照及其不同而不同,通常是前两种的一种

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航