Using Lists

A List displays several items which can be selected depending on it's choice type (either Choice.EXCLUSIVE,
Choice.MULTIPLE or Choice.IMPLICIT).
Design
The List in the screenshot above utilizes the fisheye view-type
and has been realized using the following CSS settings (without title
and menubar settings):
.mainScreen {
padding: 2;
padding-left: 10;
padding-right: 10;
background {
type: horizontal-stripes;
first-top-color: brightBgColor;
second-top-color: white;
first-bottom-color: blue;
second-bottom-color: black;
}
layout: horizontal-expand | horizontal-center | vertical-center;
//#if polish.midp2
view-type: fisheye;
fisheyeview-scale-start: 70%;
fisheyeview-scale-end: 40%;
fisheyeview-alpha-start: 200;
fisheyeview-alpha-end: 80;
fisheyeview-remove-text: true;
//#endif
//#if polish.midp2
screen-change-animation: fade;
//#endif
}
CSS Attributes for Lists
You can use the following CSS attributes for Lists:
| CSS Attribute | Default | Values | Explanation |
|---|---|---|---|
| show-text-in-title | false | true, false | Defines whether a list should show the text of the list-items in the title instead on the screen. |
| Further CSS Attribute | Default | Values | Explanation |
| always-include | false | true, false | Defines if a style should always be included, even if not used. |
| background | - | background definition | The background of an item or screen. The default background for items is "none", the default background for screens is a simple white background. |
| background-bottom | - | bottom, menubar | The bottom border of the background for this screen. Usually the background reaches to the very bottom of the screen which includes the menubar. By setting background-bottom: menubar; this background only reaches to the menubar. |
| background-top | - | top, title | The top border of the background for this screen. Usually the background reaches from the very top of the screen which includes the title. By setting background-top: title; this background starts after the title. |
| clip-screen-info | false | true, false | Enables or disables the clipping of the info-section. It is visible for TextFields in the direct input mode, for example. |
| columns | 1 | integer | The number of columns. This can be used to layout the items in a table. |
| complete-border | - | border | A border reference from the borders section. The border includes the label of the item and is independent of the item's normal border. |
| complete-background | - | background | A background name from the backgrounds section. The background includes the label of the item and is independent of the item's normal background. |
| border | - | border definition | The border of an item or screen. The default border is "none". |
| columns-width | normal | columns-width | Either "normal", "equal" or the width for each column in a comma separated list (e.g. "columns-width: 60,60,10"). |
| expand-items | false | true, false | Expands the items within a screen or container to the width of the largest item - in contrast to the expand layout not the full available width is being used. |
| focused-style | focused | style | The name of the style for the currently focused item, usually applied with a [style-name]:hover construct. |
| focused-style-first | - | style | The focused style for the first item in an Screen, ChoiceGroup, List, Container. |
| focused-style-last | - | style | The focused style for the last item in an Screen, ChoiceGroup, List, Container. |
| foreground-image | - | imageurl | The url of the image that should be shown at the topmost layer. You can also set the foreground-x and foreground-y positions. |
| foreground-x | - | integer | The x position of the foreground image. |
| foreground-y | - | integer | The y position of the foreground image. |
| inherit | true | true, false | Defines if a style that extends this style should inherit all attributes. |
| menubar-color | - | color | The color of the menu-bar. This overrides the settings in the predefined style "menu". This attribute is only used, when the "menu" fullscreen setting is activated in the "build.xml" file. |
| menubar-style | menubar | style | The name of the style for the menubar of the corresponding Screen. |
| table-selected-background | - | background | The background for selected cells of a table. |
| repaint-previous-screen | false | true, false | Specifies whether the previous screen should be repainted whenever the current screen changes, i.e. by user interaction. This makes sense when a translucent background is used for the current screen and the screen contains modifiable or selectable items. |
| screen-change-animation | - | An effect that should be shown whenever the screen is changed. | |
| screen-orientation-change-animation | - | screen-change-animation | Defines the animation that should be shown when the screen orientation is changed. Orientation changes need to be allowed by setting the preprocessing variable ScreenOrientationCanChangeManually to true. |
| scroll-mode | smooth | normal, smooth | Enables or disables the smooth scrolling function. |
| scrollbar-slider-color | black | color | The color of the slider, is ignored when a slider-image is defined. |
| scrollbar-slider-down-image | - | imageurl | The image used for signaling that the user can scroll downwards. By default nothing is painted. |
| scrollbar-slider-image-repeat | false | true, false | Either "true" or "false". When "true" is given, the slider image is repeated vertically, if necessary. |
| scrollbar-slider-mode | page | area, item, page | The mode of the slider, either "area", "item" or "page". In the "area" mode the slider represents the position of the current selection relative to the complete width and height. In the "item" mode the index of the currently selected item is taken into account relative to the number of items. In the "page" mode the height of the currently visible area will be set relative to the complete height of the screen. The default mode is "page". |
| scrollbar-slider-up-image | - | imageurl | The image used for signaling that the user can scroll upwards. By default nothing is painted. |
| scrollbar-slider-width | 2 | integer | The width of the slider in pixels, is ignored when a slider-image is defined. |
| scrollindicator-color | black | color | The color of the item which indicates that the user can scroll the current screen. Is ignored when a scrollbar is used. |
| scrollindicator-up-image | - | imageurl | The URL of the image indicating that the user can scroll upwards. |
| table-selected-row-background | - | background | The background for selected rows of a table. |
| scrollbar-slider-image | - | imageurl | The URL of image used for the slider. |
| scrollbar-style | scrollbar | style | The name of the style for the scrollbar of the corresponding Screen. |
| show-scrollbar | true | true, false | Can be used to deactivate the scrollbar for a specific screen. You need to activate scrollbar usage with polish.useScrollBar=true before using this CSS attribute. |
| table-selected-column-background | - | background | The background for selected columns of a table. |
| scrollindicator-down-image | - | imageurl | The URL of the image indicating that the user can scroll downwards. |
| separate-menu | true | true, false | Ensures that the menu is painted at the bottom of the screen without using the margins of the screen. You can apply the screen margins to the menubar as well by setting the "separate-menubar" property to "true". |
| ticker-position | top | top, bottom | You can specify the position of the ticker on the screen. |
| title-position | top | top, bottom | You can specify the position of the title on the screen. |
| title-style | title | style | The name of the style for the title of the corresponding Screen. |
| view-type | - | carousel, coverflow, dropping, fisheye, grayout, midp2, numbered, shuffle, verticalfixed | Defines another visualization for an Item or a Screen. |
| view-type-sequential-traversal | false | true, false | Defines if the cells of a table can only be traversered in sequential order. By default you can move to the next row by pressing down - when the sequential-traversal is enabled pressing down will move the focus to the next item instead. Only applicable when the columns attribute is being used. |
CSS Attributes for List-Items
For styles of List items you can use following the CSS attributes:
| CSS Attribute | Default | Values | Explanation |
|---|---|---|---|
| checkbox-plain | - | imageurlornone | The URL of the image for a not-selected item. This will be used only when the type of the list or of the choice group is multiple. Default is a simple image drawn in the defined choice-color. When "none" is given, no image will be drawn for not-selected items. Only the image for selected items will be drawn in that case. |
| checkbox-selected | - | imageurlornone | The URL of the image for a selected item. This will be used only when the type of the list or of the choice group is multiple. Default is a simple image drawn in the defined choice-color. |
| choice-color | black | color | The color in which the check- or radio-box will be painted. |
| icon-inactive | false | true, false | Can be used to deactivate a specific ChoiceGroup/List item permanently. This can be useful to integrate explanations, headings etc into an ChoiceGroup/List. |
| radiobox-plain | - | imageurlornone | The URL of the image for a not-selected item. This will be used only when the type of the list or of the choice group is exclusive. Default is a simple image drawn in the defined choice-color. When "none" is given, no image will be drawn for not-selected items. Only the image for selected items will be drawn in that case. |
| radiobox-selected | - | imageurlornone | The URL of the image for a selected item. This will be used only when the type of the list or of the choice group is exclusive. Default is a simple image drawn in the defined choice-color. |
| scale-factor | - | integer | The factor in percent by which the image should be scaled, e.g. 200. |
| scale-steps | 5 | integer | The number of intermediate steps that should be used for scaling an image. |
| text-effect | - | Sets a text effect. | |
| Further CSS Attribute | Default | Values | Explanation |
| after | - | imageurl | The URL of the image that should be shown after the item in question. |
| always-include | false | true, false | Defines if a style should always be included, even if not used. |
| background | - | background definition | The background of an item or screen. The default background for items is "none", the default background for screens is a simple white background. |
| before | - | imageurl | The URL of the image that should be shown before the item in question. |
| complete-border | - | border | A border reference from the borders section. The border includes the label of the item and is independent of the item's normal border. |
| border | - | border definition | The border of an item or screen. The default border is "none". |
| complete-background-padding | - | integer | The padding that is added to the complete-background and/or complete-border. Note that this does not change the size of the item, so you might need to adapt margins or normal paddings for your design. |
| focused-style | focused | style | The name of the style for the currently focused item, usually applied with a [style-name]:hover construct. |
| font-bitmap | - | string | Defines which bitmap (bmf) font should be used. |
| icon-horizontal-adjustment | 0 | integer | Adjusts the icon by the specified number of pixels horizontally. Negative values move the icon-image to the left. |
| icon-image | none | imageurl | The URL of the image. The keyword %INDEX% can be used for adding the position of the icon to the name, e.g."icon-image: url(icon%INDEX%.png);". |
| icon-image-align | left | left, right, top, bottom, center | The position of the image relative to the text. |
| icon-image-align-next | false | true, false | Specifies if a horizontal aligned image should be painted at the border (=default) or next to the content when the item has an expand layout. |
| icon-padding | 1 | integer | The padding between the image and the text of an icon. |
| include-label | false | true, false | Usually the label of an item is rendered separately of the item's content. You can expand the background and border over the label as well using this attribute. |
| inherit | true | true, false | Defines if a style that extends this style should inherit all attributes. |
| label-style | label | style | The name of the style for the label of the corresponding Item. |
| max-height | - | integer | The maximum height of an item. |
| max-width | - | integer | The maximum width of an item. |
| min-height | - | integer | The minimum height of an item. |
| min-width | - | integer | The minimum width of an item. |
| table-selected-background | - | background | The background for selected cells of a table. |
| colspan | 1 | integer | The number of columns wich are used by the item within a table. |
| table-selected-row-background | - | background | The background for selected rows of a table. |
| opacity | 255 | integer | The opacity of an item between 0 (fully transparent) and 255 (fully opaque). |
| pressed-style | - | style | The style which indicates that an item is being pressed, usually applied with a [style-name]:pressed construct. |
| table-selected-column-background | - | background | The background for selected columns of a table. |
| complete-background | - | background | A background name from the backgrounds section. The background includes the label of the item and is independent of the item's normal background. |
| icon-vertical-adjustment | 0 | integer | Adjusts the icon by the specified number of pixels vertically. Negative values move the icon-image to the top. |
| text-horizontal-adjustment | 0 | integer | Adjusts the text by the specified number of pixels horizontally. Negative values move the text to the left. |
| text-vertical-adjustment | 0 | integer | Adjusts the text by the specified number of pixels vertically. Negative values move the text to the top. |
| text-wrap | true | true, false | Determines wether the text should be wrapped or whether it should be kept on a single line, even when it is larger than the available width. |
| text-wrap-animate | true | true, false | You can deactivate animations for texts that should not be wrapped and which are too long for a single line. |
| text-wrap-animation-direction | both | both, left, right | The direction of the animation when the text is too wide and wrapping is deactivated. |
| text-wrap-animation-speed | 1 | integer | The speed of the animation when the text is too wide and wrapping is deactivated. |
| view-type | - | fade-in, fade-out, particle, size-decrease, size-increase | Defines another visualization for an Item or a Screen. |
| visible | true | true, false | Toggles the visibility of an item. When an item is invisible, it will not occupy any space. |
| x-adjust | 0 | integer | The horizontal position adjustment. |
Programming
Please use and import the normal javax.microedition.lcdui.List for dealing with Lists. For connecting the List and
it's items with your style definitions in polish.css use style preprocessing directives:
import javax.microedition.lcdui.List;
import de.enough.polish.ui.UiAccess;
public class MenuMidlet extends MIDlet implements CommandListener {
List menuScreen;
public MenuMidlet() {
//#style mainScreen
this.menuScreen = new List("Title", List.IMPLICIT);
//#style mainCommand
this.menuScreen.append( "Chat", null);
//#style mainCommand
this.menuScreen.append("Mail", null);
//#style mainCommand
this.menuScreen.append("Settings", null);
//#style mainCommand
this.menuScreen.append("Applications", null);
//#style mainCommand
this.menuScreen.append("Help", null);
//#style mainCommand
this.menuScreen.append("Quit", null);
//#style mainCommand
this.menuScreen.append("Documents", null);
this.menuScreen.setCommandListener(this);
this.menuScreen.addCommand( this.startGameCmd );
this.menuScreen.addCommand( this.quitCmd );
}
public startApp() {
Display display = Display.getDisplay(this);
display.setCurrent( this.menuScreen );
// pre-select Help:
UiAccess.setCurrentListIndex( display, this.menuScreen, 4 );
}
[...]
}
For accessing J2ME Polish specific List functionalities use following static de.enough.polish.ui.UiAccess methods:
addItemCommand( List list, int index, Command command ): Adds a command to the specifed List item.setCurrentListIndex( Display display, List list, int index ): Selects the specified List item and shows the List.setListItem( List list, int index, ChoiceItem item ): Sets ade.enough.polish.ui.ChoiceItemor a subclass for the given List.ChoiceItem getListItem( List list, int index ): Retrieves the specifiedde.enough.polish.ui.ChoiceItemfrom the List.appendListItem( List list, ChoiceItem item ): Appends aChoiceItemto the List.setStyle(List list, int itemIndex): Sets a style for the specified List item - use this call together with astylepreprocessing directivesetStyle(List list, int itemIndex, Style style): Sets a style programmatically for the specified List item.setAttribute( List list, int index, Object key, Object value ): Sets an arbitrary attribute for the specified List item.getAttribute( List list, int index, Object key ): Gets an previously set attribute value for the specified List itemHashMap getAttributes( List list, int index ): Retrieves all previously registered attributes from the specified ListsetAccessible(List list, int itemIndex, boolean isAccessible): Makes a List item selectable or inaccessible - can be used with astylepreprocessing directive. Make sure another List item is selected before ddeactivating a List item or callUiAccess.setCurrentListIndex()before (see above).setAccessible(List list, int itemIndex, boolean isAccessible, Style style): Same as above with a programmatically selected style.setVisible( List list, int index, boolean visible ): Toggles the visiblity of the specified List item. Note that you need to activate visible items by setting the preprocessing variablepolish.supportInvisibleItemstotruebefore this call can succeed.boolean isVisible( List list, int index ): Determines if a List item is visible.
Configuration
You can configure if List should not show commands like "Select" for implicit and exclusive Lists or "Mark"
for multiple lists. By default such commands are shown. Specify these configuration settings in the variables
section of your build.xml script.
| Variable | Default | Values | Explanation |
|---|---|---|---|
| polish.List.suppressCommands | false | true, false |
Deactivates all commands.
<variable name="polish.List.suppressCommands" value="true" /> |
| polish.List.suppressSelectCommand | false | true, false |
Deactivates the Select command for implicit and exclusive Lists.
<variable name="polish.List.suppressSelectCommand" value="true" /> |
| polish.List.suppressMarkCommands | false | true, false |
Deactivates the Mark/Unmark commands for multiple Lists.
<variable name="polish.List.suppressMarkCommands" value="true" /> |
You can also change or translate the default commands used in a List with the following settings in either messages.txt or using variables in your build.xml script. For more information about translations please refer to the localization section.
# text for the 'Select' command: polish.command.select=Choose; # texts for'Mark' and 'Unmark' commands: polish.command.mark=Select polish.command.unmark=Deselect