简体   繁体   中英

Reorder items in a spark List using drag and drop in Flex/AIR

I have a simple test example that works fine, I set the drag/drop properties to true like this: <s:List dragMoveEnabled="true" dragEnabled="true" dropEnabled="true">

The difference from the test application that works and my real application is that the layout on the real app is more complex (I am using ViewStacks and Groups) and the dataProvider. In all cases I use ArrayCollection but in the real app I have some SearchResults objects (these are not dynamic objects).

Dragging animation is there but when dropping, the item under the mouse is selected instead. If I do not set dragMoveEnabled then the item is somehow copied, but in its place I see an Object.

//Working example

<s:List dragMoveEnabled="true" dragEnabled="true" dropEnabled="true">
        <s:dataProvider>
            <s:ArrayCollection>
                <fx:Object label="Item 1" data="1" />
                <fx:Object label="Item 2" data="2" />
                <fx:Object label="Item 3" data="3" />
            </s:ArrayCollection>
        </s:dataProvider>
    </s:List>

This is from my application and is not working

<s:List id="favSavedSearchesList" width="100%" height="100%"  
        contentBackgroundColor="#dfe4ea"  
        change="favSavedSearchesList_changeHandler(event)"
        itemRenderer="generic_components.RemoveItemRenderer"
        dragMoveEnabled="true" dragEnabled="true" dropEnabled="true"/>

Update: I made some tests and replaced my dataProvider with an ArrayCollection of Strings and it worked, so I can now exclude the complex layout of the application and looking at the provider

I found the problem by debugging the drop handler of the List. The problem was caused by the fact the dataProvider had a sort set, if you have sorted the ArrayCollection or the Array used to create the dataProvider then the dragMove is ignored.

Second issue is my Array was obtain by reading from a sqlite database and I did not set a sort on it in code or in the SQL query so the sorting thing was unexpected for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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