我在flex mobile List组件中使用项呈示器,项呈示器必须根据接收的输入数据逐行显示不同的图像。我在项目渲染器的creationComplete中执行这些所有控件,这样如果它的“X”使图像源成为这一个等等。但是当我在创建List之后滚动它时,它会以不同的顺序重置项目,这样如果“Item1”是在滚动后的第一行列表中,它转到最后一行,最后一行转到第一行。
列出组件代码:
<s:List id="lst" dataProvider="{dp}" width="100%" height="100%"
itemRenderer="renderer.YataklarViewRenderer"
contentBackgroundAlpha="0" borderColor="#FFFFFF" borderVisible="true" >
<s:layout>
<s:VerticalLayout
horizontalAlign="center"
paddingBottom="10"
paddingTop="10"
paddingLeft="10"
paddingRight="10"
/>
</s:layout>
</s:List>
项目渲染器代码:
protected function yataklarItem_creationCompleteHandler(event:FlexEvent):void
{
trace("Creation complete: "+ data['servisAdi']);
var servisAdi:String = data['servisAdi'];
//header text ekle
this.addElement(header);
header_text.text = servisAdi;
var odalar:ArrayCollection = new ArrayCollection();
odalar = data['odalar'];
for(var i:int=0;i<odalar.length;i++){
var mainContent:VGroup = new VGroup();
// mainContent.paddingBottom
mainContent.percentWidth = 100;
mainContent.percentWidth = 100;
mainContent.horizontalAlign = "center";
mainContent.verticalAlign = "middle";
var hContent:HGroup = new HGroup();
hContent.percentWidth = 100;
hContent.verticalAlign = "middle";
hContent.horizontalAlign = "left";
var col1:HGroup = new HGroup();
col1.percentWidth = 10;
col1.verticalAlign = "middle";
col1.horizontalAlign = "center";
var col2:HGroup = new HGroup();
col2.percentWidth = 20;
col2.verticalAlign = "middle";
col2.horizontalAlign = "center";
var imgCol:Image = new Image();
var txtOdaAdi:Label = new Label();
var oda:Object = new Object();
oda = odalar.getItemAt(i);
var odaAdi:String = oda['odaAdi'];
var baskinCinsiyyet:String = oda['baskinCinsiyet'];
txtOdaAdi.text = odaAdi;
imgCol.source = "images/yataklar/baskin"+baskinCinsiyyet+".png";
col1.addElement(imgCol);
col2.addElement(txtOdaAdi);
var ytk:ArrayCollection = new ArrayCollection();
ytk = oda['yataklar'];
var yataklarCol:HGroup = new HGroup();
yataklarCol.percentWidth = 70;
yataklarCol.horizontalAlign = "left";
yataklarCol.verticalAlign = "center";
for( var j:int=0;j<ytk.length;j++){
var yatakG:VGroup = new VGroup();
yatakG.gap = 5;
yatakG.horizontalAlign = "center";
yatakG.verticalAlign = "middle";
var yatak:Object = new Object();
yatak = ytk.getItemAt(j);
var yatakNo:int = yatak['yatakNo'];
var durumu:String = yatak['durumu'];
//uzerine tiklandiginda
var vizitId:String = yatak['vizitId'];
var hastaId:String = yatak['hastaId'];
var adiSoyadi:String = yatak['adiSoyadi'];
var txtYatakNo:Label = new Label();
txtYatakNo.text = yatakNo.toString();
var imgYatakImg:Image = new Image();
imgYatakImg.source = "images/yataklar/yatak"+durumu+".png";
yatakG.addElement(imgYatakImg);
yatakG.addElement(txtYatakNo);
yataklarCol.addElement(yatakG);
}
hContent.addElement(col1);
hContent.addElement(col2);
hContent.addElement(yataklarCol);
mainContent.addElement(hContent);
mainContent.addElement(line);
this.addElement(mainContent);
}
}
<fx:Declarations>
<s:Group id="header" width="100%" height="50">
<s:Rect
width="100%" height="100%">
<s:fill>
<s:LinearGradient rotation="90">
<s:GradientEntry color="0x314F83" />
</s:LinearGradient>
</s:fill>
</s:Rect>
<s:VGroup id="vgt" paddingBottom="10" paddingTop="10" paddingLeft="10" paddingRight="10" gap="10" width="100%"
verticalAlign="middle" horizontalAlign="left" height="100%">
<s:Label id="header_text" color="#FFFFFF" verticalAlign="middle" height="100%"/>
</s:VGroup>
</s:Group>
<s:Line id="line" width="100%">
<s:stroke>
<s:SolidColorStroke color="0x5b5b5b" weight="2"/>
</s:stroke>
</s:Line>
</fx:Declarations>
<s:layout>
<s:VerticalLayout verticalAlign="top" horizontalAlign="center" />
</s:layout>
我认为我的代码中的所有内容都是正确的,但我必须添加一些额外的行。任何人都可以帮我解决这个棘手的问题吗?
答案 0 :(得分:1)
在项目渲染器的creationComplete中执行这些所有控件,以便if 它的“X”使这个图像的来源等。
这是一个问题。 Flex列表仅呈现屏幕上显示的内容,它们不会呈现屏幕外的内容。滚动渲染器时,将重新使用渲染器,而不会创建新的渲染器。将不再触发creationComplete事件以更新正在显示的数据的呈现。
重新使用渲染器的过程称为渲染器回收。要正确创建渲染器,您必须侦听dataChange事件以根据数据调整渲染器显示。
有些人更喜欢在itemRenderer中覆盖set data方法并在那里进行更改。这也是一种同样可以接受的方法。
将useVirtualLayout设置为false的原因是因为它告诉列表单独呈现每个项目而不使用渲染器回收。这不是移动设备在性能或内存使用方面的最佳选择。
Please read the docs on using the data property in itemRenderers
答案 1 :(得分:0)
添加<s:List useVirtualLayout="false">
为我解决了问题!