How to get visible items in Spark List with virtual layout
I have:
- ArrayCollection of Numbers;
- a List using the above ArrayCollection, since it is dataprovider and virtualLayout = true;
- a custom ItemRenderer that shows the label with: a) number b) y position versus number AND most visible
In other words, if I have 10 numbers in AC and only 5 appears on the screen, the y-position of those 5 will depend on the value of the maximum number for them. 5. When the user scrolls, of course the 5 items change, so the position of the label in the item renderers will change.
My questions:
1) How can I get a list of the currently visible items? 2) What event / method override will help me know that the list has been scrolled / visible items have changed?
Thank,
Joao Saliro
+2
source to share
3 answers
I solved the problem this way:
protected function pagedList_touchInteractionEndHandler(event:TouchInteractionEvent):void
{
var _index:int = (event.currentTarget.scroller.viewport.layout.horizontalScrollPosition / event.currentTarget.scroller.viewport.layout.columnWidth);
}
<s:List id="pagedList" scrollSnappingMode="center" selectionColor="#FFFFFF" downColor="#FFFFFF" focusAlpha="0"
width="100%" height="100%" useVirtualLayout="true"
verticalScrollPolicy="off" horizontalScrollPolicy="on"
pageScrollingEnabled="true"
itemRenderer="myItemRender"
skinClass="skins.PagedListSkin"
touchInteractionStart="pagedList_touchInteractionStartHandler(event)" touchInteractionEnd="pagedList_touchInteractionEndHandler(event)" >
<s:layout>
<s:TileLayout orientation="rows" requestedRowCount="1"
columnWidth="{pagedList.width}" rowHeight="{pagedList.height}"
verticalGap="0" horizontalGap="0" />
</s:layout>
</s:List>
+1
source to share