Displaying the row number or index in a spark List
[url]http://flexponential.com/2010/02/08/displaying-the-row-number-or-index-in-a-spark-list/[/url]
[img]http://dl.iteye.com/upload/attachment/206948/30c22f1d-5601-38fe-aa1f-5cdea7aa49fd.jpg[/img]
[url]http://flexponential.com/2010/02/08/displaying-the-row-number-or-index-in-a-spark-list/[/url]
[img]http://dl.iteye.com/upload/attachment/206948/30c22f1d-5601-38fe-aa1f-5cdea7aa49fd.jpg[/img]
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" width="200" height="215" viewSourceURL="srcview/index.html">
<s:List height="200" width="200" top="10">
<s:layout>
<s:VerticalLayout gap="1" horizontalAlign="justify" />
</s:layout>
<s:dataProvider>
<s:ArrayList>
<fx:String>Roberto Luongo</fx:String>
<fx:String>Scott Niedermayer</fx:String>
<fx:String>Jarome Iginla</fx:String>
<fx:String>Dan Boyle</fx:String>
<fx:String>Rick Nash</fx:String>
<fx:String>Ryan Getzlaf</fx:String>
<fx:String>Martin Brodeur</fx:String>
<fx:String>Chris Pronger</fx:String>
<fx:String>Shane Doan</fx:String>
<fx:String>Shea Weber</fx:String>
<fx:String>Patrick Marleau</fx:String>
<fx:String>Jay Bouwmeester</fx:String>
<fx:String>Duncan Keith</fx:String>
<fx:String>Dany Heatley</fx:String>
<fx:String>Robyn Regehr</fx:String>
<fx:String>Mike Richards</fx:String>
<fx:String>Brenden Morrow</fx:String>
<fx:String>Martin St. Louis</fx:String>
<fx:String>Jeff Carter</fx:String>
<fx:String>Eric Staal</fx:String>
<fx:String>Sidney Crosby</fx:String>
</s:ArrayList>
</s:dataProvider>
<s:itemRenderer>
<fx:Component>
<s:ItemRenderer>
<fx:Script>
<![CDATA[
import spark.components.List;
override public function set data(value:Object):void {
super.data = value;
if (value == null)
return;
txtPlayer.text = String(data);
txtRowNumber.text = String(itemIndex);
// NOTE: In older builds ItemRenderer.itemIndex didn't exist yet. If you are on an older
// build you can get this information using the following line instead:
//
//txtRowNumber.text = String((owner as List).dataProvider.getItemIndex(data));
}
]]>
</fx:Script>
<s:Group>
<s:Rect width="25" height="20">
<s:fill>
<s:SolidColor color="0xFF0000" />
</s:fill>
</s:Rect>
<s:Label id="txtRowNumber" color="white" fontWeight="bold" horizontalCenter="0" verticalCenter="0" />
</s:Group>
<s:Label id="txtPlayer" x="30" verticalCenter="0" />
</s:ItemRenderer>
</fx:Component>
</s:itemRenderer>
</s:List>
</s:Application>