您的位置:首页 >> 编程开发 >> Java >> JDK核心API >> 正文
JDK核心API RSS
 

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

http://www.rdxx.com 05年07月27日 22:31 CSDN 我要投稿

关键词: 手机 , 读书笔记 , 程序设计 , PDA , LCD , Java , 入门 , API , UI , 程序 , 设计 , cd , PD
 

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



 
 
标签: 手机 , 读书笔记 , 程序设计 , PDA , LCD , Java , 入门 , API , UI , 程序 , 设计 , cd , PD 打印本文
 
 
  热点搜索
 
 
 



Valid XHTML 1.0 Transitional
Copyright ©2005 - 2008 Rdxx.Com,All Rights Reserved
收藏本页
收藏本站