简体   繁体   English

Flex Mobile防止回收项目渲染器状态

[英]Flex mobile prevent item renderer state from recycled

I have this custom list item renderer where I have defined 2 custom states: 我有这个自定义列表项渲染器,其中定义了2个自定义状态:

<s:states>
    <s:State name="expand"/>
    <s:State name="collapse"/>
</s:states>

When I select one of the list item, it will change to state collapse. 当我选择列表项之一时,它将变为状态折叠。 Now whenever I select the first or the last item in the list and I refresh the data provider, the current state of both the items will swap places. 现在,每当我选择列表中的第一个或最后一个项目并刷新数据提供程序时,这两个项目的当前状态都会交换位置。

Please guide me on how to retain the state of the itemrenderer. 请指导我如何保留itemrenderer的状态。 Thank you. 谢谢。

Note: It all works well when I change the usevirtuallayout to false. 注意:当我将usevirtuallayout更改为false时,一切都很好。 But, it is not what I intended to change. 但是,这不是我要更改的内容。

[Edit] The following is my code for the item renderer: [编辑]以下是我的项目渲染器代码:

<fx:Script>
    <![CDATA[

protected function init(event):void
{
    currentState = "collapse";
}

override public function set data(value:Object):void 
{
    trace(currentState.toString());
}

protected function btn_clickHandler(event:MouseEvent):void
{
    currentState = "expand";
}

]]>
</fx:Script>

<s:states>
    <s:State name="expand"/>
    <s:State name="collapse"/>
</s:states>

<s:Button id="changeStateButton" click="btn_clickHandler(event)"/>

The example above is a simple item renderer where a single button will change the currentState of the itemrenderer. 上面的示例是一个简单的项目渲染器,其中一个按钮将更改项​​目渲染器的currentState。 I have 3 items in the data provider and each one of them is in the "collapse" state by default. 我在数据提供程序中有3个项目,默认情况下,每个项目都处于“折叠”状态。 This is the trace result from the set data function: 这是来自设置数据功能的跟踪结果:

collapse
collapse
collapse

When I click the button at the last item... this will be the trace result: 当我单击最后一项的按钮时...这将是跟踪结果:

collapse
collapse
expand

Now, when I refresh the data provider by calling this function "arraycollection.refresh()"...this is the result: 现在,当我通过调用此函数“ arraycollection.refresh()”刷新数据提供程序时,结果如下:

expand
collapse
collapse

Can somebody explain this scenario? 有人可以解释这种情况吗? Notice that this only happens when the useVirtualLayout is set to true... 请注意,只有在useVirtualLayout设置为true时才会发生这种情况。

Try reassigning the item renderer after updating the data provider. 更新数据提供程序后,尝试重新分配项目渲染器。

//update data provider
itemList.dataProvider = myCollection;
//update the item renderer
itemList.itemRenderer = new ClassFactory(cutomItemRenderer);

This solution of course will be more resource intensive. 当然,这种解决方案将需要更多的资源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM