{@code}
name
attribute defines the name of the style which you can later use with {@link Skin#newList(String,String[],String)}.fontName
attribute references a {@link BitmapFont} by name, to be used for render the itemsfontColorUnselected
attribute references a {@link Color} by name, to be used for render unselected itemsfontColorSelected
attribute references a {@link Color} by name, to be used to render the selected itemselected
attribute references a {@link NinePatch} by name, to be used to render the highlight behind theselected itemList
contains several ListItem
s. Example 1:
The result of this code looks like this:List list = new List(true, 20); list.add(new ListItem("First line")); list.add(new ListItem("The second line is longer to see what happens once the end of the line is reached. Will it start on a new line?")); list.add(new ListItem("Third line"));
The result of this code looks like this:List overview = new List(false, 10); overview.add(new ListItem("This is an item")); overview.add("This is another item");
List
contains several ListItem
s. Example 1:
The result of this code looks like this:List list = new List(true, 20); list.add(new ListItem("First line")); list.add(new ListItem("The second line is longer to see what happens once the end of the line is reached. Will it start on a new line?")); list.add(new ListItem("Third line"));
The result of this code looks like this:List overview = new List(false, 10); overview.add(new ListItem("This is an item")); overview.add("This is another item");
A list can represent many UI concepts ranging from a carousel to a "todo" checklist, this is made possible thanks to extensive use of Swing's style of MVC. Specifically a list component is relatively simple, it invokes the model in order to extract the displayed/selected information and shows it to the user by invoking the cell renderer.
The list class itself is completely decoupled from everything, thus it allows us to extract its content from any source (e.g. network, storage etc.) and display the information in any form (e.g. checkboxed elemenents, icons etc.). @see com.sun.lwuit.list @author Chen Fishbein
List
component presents the user with a scrolling list of text items. The list can be set up so that the user can choose either one item or multiple items. For example, the code . . .
List lst = new List(4, false); lst.add("Mercury"); lst.add("Venus"); lst.add("Earth"); lst.add("JavaSoft"); lst.add("Mars"); lst.add("Jupiter"); lst.add("Saturn"); lst.add("Uranus"); lst.add("Neptune"); lst.add("Pluto"); cnt.add(lst);
where cnt
is a container, produces the following scrolling list:
If the List allows multiple selections, then clicking on an item that is already selected deselects it. In the preceding example, only one item from the scrolling list can be selected at a time, since the second argument when creating the new scrolling list is false
. If the List does not allow multiple selections, selecting an item causes any other selected item to be deselected.
Note that the list in the example shown was created with four visible rows. Once the list has been created, the number of visible rows cannot be changed. A default List
is created with four rows, so that lst = new List()
is equivalent to list = new List(4, false)
.
Beginning with Java 1.1, the Abstract Window Toolkit sends the List
object all mouse, keyboard, and focus events that occur over it. (The old AWT event model is being maintained only for backwards compatibility, and its use is discouraged.)
When an item is selected or deselected by the user, AWT sends an instance of ItemEvent
to the list. When the user double-clicks on an item in a scrolling list, AWT sends an instance of ActionEvent
to the list following the item event. AWT also generates an action event when the user presses the return key while an item in the list is selected.
If an application wants to perform some action based on an item in this list being selected or activated by the user, it should implement ItemListener
or ActionListener
as appropriate and register the new listener to receive events from this list.
For multiple-selection scrolling lists, it is considered a better user interface to use an external gesture (such as clicking on a button) to trigger the action. @version 1.110, 07/11/06 @author Sami Shaio @see java.awt.event.ItemEvent @see java.awt.event.ItemListener @see java.awt.event.ActionEvent @see java.awt.event.ActionListener @since JDK1.0
Unlike sets, lists typically allow duplicate elements. More formally, lists typically allow pairs of elements e1 and e2 such that e1.equals(e2), and they typically allow multiple null elements if they allow null elements at all. It is not inconceivable that someone might wish to implement a list that prohibits duplicates, by throwing runtime exceptions when the user attempts to insert them, but we expect this usage to be rare.
The List interface places additional stipulations, beyond those specified in the Collection interface, on the contracts of the iterator, add, remove, equals, and hashCode methods. Declarations for other inherited methods are also included here for convenience.
The List interface provides four methods for positional (indexed) access to list elements. Lists (like Java arrays) are zero based. Note that these operations may execute in time proportional to the index value for some implementations (the LinkedList class, for example). Thus, iterating over the elements in a list is typically preferable to indexing through it if the caller does not know the implementation.
The List interface provides a special iterator, called a ListIterator, that allows element insertion and replacement, and bidirectional access in addition to the normal operations that the Iterator interface provides. A method is provided to obtain a list iterator that starts at a specified position in the list.
The List interface provides two methods to search for a specified object. From a performance standpoint, these methods should be used with caution. In many implementations they will perform costly linear searches.
The List interface provides two methods to efficiently insert and remove multiple elements at an arbitrary point in the list.
Note: While it is permissible for lists to contain themselves as elements, extreme caution is advised: the equals and hashCode methods are no longer well defined on such a list.
Some list implementations have restrictions on the elements that they may contain. For example, some implementations prohibit null elements, and some have restrictions on the types of their elements. Attempting to add an ineligible element throws an unchecked exception, typically NullPointerException or ClassCastException. Attempting to query the presence of an ineligible element may throw an exception, or it may simply return false; some implementations will exhibit the former behavior and some will exhibit the latter. More generally, attempting an operation on an ineligible element whose completion would not result in the insertion of an ineligible element into the list may throw an exception or it may succeed, at the option of the implementation. Such exceptions are marked as "optional" in the specification for this interface.
This interface is a member of the Java Collections Framework. @author Josh Bloch @author Neal Gafter @version 1.49, 04/21/06 @see Collection @see Set @see ArrayList @see LinkedList @see Vector @see Arrays#asList(Object[]) @see Collections#nCopies(int,Object) @see Collections#EMPTY_LIST @see AbstractList @see AbstractSequentialList @since 1.2
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|