Skip navigation
Currently Being Moderated

ItemRenderer and updateDisplayList problem

Dec 23, 2011 3:58 AM

Tags: #itemrenderer #datagrid #updatedisplaylist

I looked over the internet about ItemRenderer and I got some information about the fact that itemrenderer is reused after scrolling instead of creating new Object for every cells...

I have a custom ItemRenderer that color the cell based on the value of data on creation it display the cell correctly, scrolling the grid the itemrenderer is reused and I got a strange behaviour..

I tried to reset the color and the text label before check for the value of data (in updatedisplaylist) but without luck..

 

here my ItemRendererCode

 

I tried to put the `super.updateDisplayList(..) at the top and at the bottom of the function but without changes...

 

 

Help!!!!

 

 

<?xml version="1.0" encoding="utf-8"?>
<s:GridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
               
xmlns:s="library://ns.adobe.com/flex/spark" minHeight="14">

<fx:Script>
    <![CDATA[
        import emobyClass.AgendaItems;
        import emobyClass.Appuntamento;        

        override protected function updateDisplayList(unscaledWidth:Number,                    
                                                      unscaledHeight:Number):void
        {

            back.color = 0xffffff;
            labelInsegna.text = "";
            labelVia.text = "";
            labelCitta.text="";
            if (data!=null)
            {                  
                var f:String = column.dataField;
                if (data[f]!="")
                {
                    var tmp:AgendaItems = data[f];
                    var app:Appuntamento = tmp.appuntamento;
                    back.color = 0xffd300;                 
                    rect.bottom = -22;
                    if (tmp.isStart){                          
                        rect.topRightRadiusX = 30;
                        rect.topLeftRadiusX = 30;
                    }
                    if (tmp.isEnd)
                    {
                        rect.bottom = -2;
                        rect.bottomLeftRadiusX = 30;
                        rect.bottomRightRadiusX = 30;
                    }                                              
                        if (tmp.isStart)
                        {
                            labelInsegna.setStyle("fontSize",20);
                            labelVia.setStyle("fontSize",20);
                            labelInsegna.height = height/3;
                            labelInsegna.top = 0;
                            labelVia.height = height/3;                            
                            labelVia.top = labelInsegna.height;                            
                            labelCitta.setStyle("fontSize",20);                            
                            labelCitta.height = height/3;
                            labelCitta.top = labelInsegna.height*2;
                            labelInsegna.text = "(D) " + app.insegna;
                            labelVia.text = app.indirizzo;
                            labelCitta.text=app.citta;
                        }
                }
            }
            super.updateDisplayList(width, height);
        }

    ]]>
</fx:Script>

<s:Rect top="-2" bottom="-2" right="-1" left="-1">
   
<s:fill>
       
<s:SolidColor color="#ffffff" alpha="1"/>
   
</s:fill>
</s:Rect>  


<!--<s:Rect id="border" top="0" bottom="0" right="0" left="0">
    <s:fill>
        <s:SolidColor id="borderColor" color="#000000" alpha="1"/>
    </s:fill>
</s:Rect> -->


<s:Rect id="rect" top="-2" bottom="-2" right="0" left="0">
   
<s:fill>
       
<s:SolidColor id="back" color="#eaeaea" alpha="1"/>
   
</s:fill>
</s:Rect>  


<s:Label id="labelInsegna"                                                                                                         
        
textAlign="left"
        
fontFamily="Verdana"
        
fontWeight="bold"
        
maxDisplayedLines="1"
        
left="4" right="2"
        
verticalAlign="middle"
        
showTruncationTip="true"/>
<s:Label id="labelVia" textAlign="left" maxDisplayedLines="1"
        
fontFamily="Verdana"
        
verticalAlign="middle"
        
left="4" right="2"
        
showTruncationTip="true"/>
<s:Label id="labelCitta" textAlign="left" maxDisplayedLines="1"
        
fontFamily="Verdana"
        
verticalAlign="middle"
        
left="4" right="2"
        
showTruncationTip="true"/>

 
Replies
  • Currently Being Moderated
    Dec 23, 2011 10:45 PM   in reply to Z4g0s

    When recycling renderers, it is important to have an else clause for every if.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points