簡體   English   中英

Flex Mobile防止回收項目渲染器狀態

[英]Flex mobile prevent item renderer state from recycled

我有這個自定義列表項渲染器,其中定義了2個自定義狀態:

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

當我選擇列表項之一時,它將變為狀態折疊。 現在,每當我選擇列表中的第一個或最后一個項目並刷新數據提供程序時,這兩個項目的當前狀態都會交換位置。

請指導我如何保留itemrenderer的狀態。 謝謝。

注意:當我將usevirtuallayout更改為false時,一切都很好。 但是,這不是我要更改的內容。

[編輯]以下是我的項目渲染器代碼:

<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)"/>

上面的示例是一個簡單的項目渲染器,其中一個按鈕將更改項​​目渲染器的currentState。 我在數據提供程序中有3個項目,默認情況下,每個項目都處於“折疊”狀態。 這是來自設置數據功能的跟蹤結果:

collapse
collapse
collapse

當我單擊最后一項的按鈕時...這將是跟蹤結果:

collapse
collapse
expand

現在,當我通過調用此函數“ arraycollection.refresh()”刷新數據提供程序時,結果如下:

expand
collapse
collapse

有人可以解釋這種情況嗎? 請注意,只有在useVirtualLayout設置為true時才會發生這種情況。

更新數據提供程序后,嘗試重新分配項目渲染器。

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

當然,這種解決方案將需要更多的資源。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM