List是一个包含选项的Screen。List的大多数方法和ChoiceGroup相同。不同的List类型是由Choice接口来定义的。当一个List显示在屏幕上时,用户可以通过选择选项或是上下滚动等可能的方式同它交互。滚动不会引起应用程序可见的事件发生。只有当一个Command被传递给CommandListener时系统才会通知应用程序。List类还支持一个设备独立的特殊的select命令。
对List元素的select操作的概念是用户同List交互的核心。在一个专门有”select”或是”go”按钮的设备上,select操作由这些按键来实现。设备不支持硬件按钮的必须为select操作提供另外的方法,比如,用soft key。后面将描述不同类型的List里select操作的行为。
List对象可以用这几种Choice type建立:Choice.EXCLUSIVE,Choice.MULIPLE,Choice.IMPLICIT。List对象不能用Choice.POPUP建立。
EXCLUSIVE
和 MULTIPLE List
里的selection
操作
在这里select操作不和Command对象相联,所以应用程序没有必要为其设置label或是在执行select操作时被通知。在EXCLUSIVE类型里,select操作选中目标元素并取消对先前元素的选择。在MULTIPLE类型里,select操作在选定目标元素的同时保持其它元素状态不变。用soft key来执行select操作的设备需要为该操作提供一个label。建议在EXCLUSIVE里,label是”Select”,在MULTIPLE里是”Mark”或是”Unmark”。
IMPLICIT
里的select
操作
在这里select操作同一个被称做select command的Command对象相关联。当用户执行select操作时,系统把select command传递给List的CommandListener。缺省的select command是系统定义的command SELECT_COMMAND。应用程序可以调用setSelectCommand方法来修改select command。用soft key来执行select operation的设备使用select command的label。如果select command是SELECT_COMMAND,设备可能会用自定义的label代替SELECT_COMMAND的label域。应用程序通常应该提供自己的select command来代替SELECT_COMMAND。这使得应用程序可以选取一个有意义的label,而不是系统提供给SELECT_COMMAND的。如果List里没有元素系统就不能调用select command,因为如果List为空就没有可选择项。这种情况下系统应该移除或是使显示在menu中的soft button无效。其它command仍可以正常调用。
IMPLICIT List
的用法
IMPLICIT .List可以通过向List里添加元素来构建菜单。应用程序提供一个Command用来选择List元素并把该Command设定为select command。应用程序还需要注册一个CommandListener,在用户选择或是触发Command时调用:
String[] elements = { ... }; //Menu元素就是List 元素
List menuList = new List("Menu", List.IMPLICIT, elements, null);
Command selectCommand = new Command("Open", Command.ITEM, 1);
menuList.setSelectCommand(selectCommand);
menuList.setCommandListener(...);
监听器查询List确定被选中的元素并执行相应的操作。注意把一个command设为select commnd的同时为把该command添加到List里。
Select command应该被认为是当select键按下后的缺省行为。比如,一个显示email标题的List拥有三种操作:阅读,回复,删除。阅读为缺省操作。
List list = new List("Email", List.IMPLICIT, headers);
readCommand = new Command("Read", Command.ITEM, 1);
replyCommand = new Command("Reply", Command.ITEM, 2);
deleteCommand = new Command("Delete", Command.ITEM, 3);
list.setSelectCommand(readCommand);
list.addCommand(replyCommand);
list.addCommand(deleteCommand);
list.setCommandListener(...);
在一个有select按键的设备里,按下此键会引发readCommand。在一个没有select按键的设备里,用户仍能调用read命令,因为它还是一个独立的Command。
值得注意的是使用缺省操作必须仔细考虑,总是记住用户界面的可用性。缺省操作应该是那些List里最直接的操作。
javax.microedition.lcdui
Class List
Class List
java.lang.Object javax.microedition.lcdui.Displayable javax.microedition.lcdui.Screen javax.microedition.lcdui.List
All Implemented Interfaces:
Choice
public class
List
extends Screen
implements Choice
A
Screen
containing list of choices. Most of its behavior is common with class
ChoiceGroupList
types in particular, are defined in interface ChoiceList
is present on the display, the user can interact with it by selecting elements and possibly by traversing and scrolling among them. Traversing and scrolling operations do not cause application-visible events. The system notifies the application only when a CommandList
class also supports a select command that may be invoked specially depending upon the capabilities of the device.
is invoked by notifying its CommandListener
. The
. When a
, and their common API. The different
The notion of a
select operation on a
List
element is central to the user's interaction with the
List
. On devices that have a dedicated hardware "select" or "go" key, the select operation is implemented with that key. Devices that do not have a dedicated key must provide another means to do the select operation, for example, using a soft key. The behavior of the select operation within the different types of lists is described in the following sections.
List
objects may be created with
Choice
types of
Choice.EXCLUSIVEChoice
type Choice.POPUPList
objects.
is not allowed on
,
Choice.MULTIPLE
, and
Choice.IMPLICIT
. The
Selection in
EXCLUSIVE
and MULTIPLE
Lists
The select operation is not associated with a
Command
object, so the application has no means of setting a label for it or being notified when the operation is performed. In
Lists
of type
EXCLUSIVE
, the select operation selects the target element and deselects the previously selected element. In
Lists
of type
MULTIPLE
, the select operation toggles the selected state of the target element, leaving the selected state of other elements unchanged. Devices that implement the select operation using a soft key will need to provide a label for it. The label should be something similar to "Select" for
Lists
of type
EXCLUSIVE
, and it should be something similar to "Mark" or "Unmark" for
Lists
of type
MULTIPLE
.
Selection in
IMPLICIT
Lists
The select operation is associated with a
Command
object referred to as the
select command. When the user performs the select operation, the system will invoke the select command by notifying the
List's
CommandListenerSELECT_COMMAND
. The select command may be modified by the application through use of the setSelectCommandSELECT_COMMAND
, the device may choose to provide its own label instead of using the label attribute of SELECT_COMMAND
. Applications should generally provide their own select command to replace SELECT_COMMAND
. This allows applications to provide a meaningful label, instead of relying on the one provided by the system for SELECT_COMMAND
. The implementation must not invoke the select command if there are no elements in the List
, because if the List
is empty the selection does not exist. In this case the implementation should remove or disable the select command if it would appear explicitly on a soft button or in a menu. Other commands can be invoked normally when the List
is empty.
method. Devices that implement the select operation using a soft key will use the label from the select command. If the select command is
. The default select command is the system-provided command
Use of
IMPLICIT
Lists
IMPLICIT
Lists
can be used to construct menus by providing operations as
List
elements. The application provides a
Command
that is used to select a
List
element and then defines this
Command
to be used as the select command. The application must also register a
CommandListener
that is called when the user selects or activates the
Command
:
|
The listener can query the
List
to determine which element is selected and then perform the corresponding action. Note that setting a command as the select command adds it to the
List
as a side effect.
The select command should be considered as a
default operation that takes place when a select key is pressed. For example, a
List
displaying email headers might have three operations: read, reply, and delete. Read is considered to be the default operation.
|
On a device with a dedicated select key, pressing this key will invoke
readCommand
. On a device without a select key, the user is still able to invoke the read command, since it is also provided as an ordinary
Command
.
It should be noted that this kind of default operation must be used carefully, and the usability of the resulting user interface must always kept in mind. The default operation should always be the most intuitive operation on a particular List.
Since:
MIDP 1.0
翻译:lori.wang