items as List elements List menuList = new List("Menu", List.IMPLICIT, elements, null); Command selectCommand = new Command("Open", Command.ITEM, 1); menuList.setSelectCommand(selectCommand); menuList.setCommandListener(...);
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.
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(...); |
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