class ListView
package feathers.controls
extends BaseScrollContainer › FeathersControl › MeasureSprite › ValidatingSprite
implements IDataSelector<Dynamic>
Displays a one-dimensional list of items. Supports scrolling, custom item renderers, and custom layouts.
Layouts may be, and are highly encouraged to be, virtual, meaning that the list view is capable of creating a limited number of item renderers to display a subset of the data provider that is currently visible, instead of creating a renderer for every single item. This allows for optimized performance with very large data providers.
The following example creates a list view, gives it a data provider, tells the item renderer how to interpret the data, and listens for when the selection changes:
var listView = new ListView();
listView.dataProvider = new ArrayCollection(
[
{ text: "Milk" },
{ text: "Eggs" },
{ text: "Bread" },
{ text: "Chicken" },
]);
listView.itemToText = (item:Dynamic) ->
{
return item.text;
};
listView.addEventListener(Event.CHANGE, (event:Event) ->
{
var listView = cast(event.currentTarget, ListView);
trace("ListView changed: " + listView.selectedIndex + " " + listView.selectedItem.text);
});
this.addChild(listView);
1.0.0
.See:
Constructor
Variables
dataProvider:IFlatCollection<Dynamic> = null
The collection of data displayed by the list.
The following example passes in a data provider and tells the item renderer how to interpret the data:
list.dataProvider = new ArrayCollection(
[
{ text: "Milk" },
{ text: "Eggs" },
{ text: "Bread" },
{ text: "Chicken" },
]);
list.itemToText = (item:Dynamic) ->
{
return item.text;
};
1.0.0
.See:
itemRendererRecycler:DisplayObjectRecycler<Dynamic, ListViewItemState, DisplayObject> = DisplayObjectRecycler.withClass(ItemRenderer)
Manages item renderers used by the list view.
In the following example, the list view uses a custom item renderer class:
list.itemRendererRecycler = DisplayObjectRecycler.withClass(CustomItemRenderer);
1.0.0
.layout:ILayout = null
The layout algorithm used to position and size the list view's items.
By default, if no layout is provided by the time that the list initializes, a default layout that displays items vertically will be created.
The following example tells the list to use a horizontal layout:
var layout = new HorizontalLayout();
layout.gap = 20.0;
layout.padding = 20.0;
list.layout = layout;
1.0.0
.selectable:Bool = true
Determines if items in the list view may be selected. By default only a single item may be selected at any given time. In other words, if item A is already selected, and the user selects item B, item A will be deselected automatically.
The following example disables selection of items in the list view:
list.selectable = false;
See:
Methods
dynamicitemToText (data:Dynamic):String
Converts an item to text to display within list view. By default, the
toString()
method is called to convert an item to text. This method
may be replaced to provide custom text.
For example, consider the following item:
{ text: "Example Item" }
If the ListView
should display the text "Example Item", a custom
implementation of itemToText()
might look like this:
list.itemToText = (item:Dynamic) ->
{
return item.text;
};
1.0.0
.