Flex List Controls - A Reusable Item Renderer (
Page 4 of 4 )
As stated earlier, here is the same application, but this code uses a reusable itemRenderer:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx=http://www.adobe.com/2006/mxml
layout="absolute">
<mx:Component id="myItemRenderer"> <mx:HBox> <mx:CheckBox/>
<mx:Label text="{data.@label}"/>
</mx:HBox> </mx:Component> <mx:Panel title="My List" width="100%">
<mx:List labelField="@label" width="100%" itemRenderer="{myItemRenderer}">
<mx:dataProvider>
<mx:XMLList xmlns="">
<fruit label="Apple"/>
<fruit label="Orange"/>
<fruit label="Cherry"/>
<fruit label="Mango"/>
<fruit label="Peach"/>
<fruit label="Plum"/>
<fruit label="Banana"/>
</mx:XMLList>
</mx:dataProvider>
</mx:List>
</mx:Panel>
</mx:Application>
Notice the declaration of the <mx:Component> tag outside of out <mx:List> tag. Now that this definition is not tied to the list control, and other data aware control can use it as an item renderer.
There you have it. A easy introduction into the List Control and Item Renderers. Enjoy.