4 Replies Latest reply on Feb 25, 2010 12:16 PM by Peter deHaan

    Spark List states

    franto kormanak Level 1

      Hey,

       

      is it possible to disable selection in spark List, so there will be just state 'normal' and 'hovored', but not 'selected' state? Or is it possible to have something like 'selectedHovered'? I really dont like, that selecteion has not rollover built in (at least I'm not aware fo it)

       

      THanks

        • 1. Re: Spark List states
          David_F57 Level 5

          Hi,

           

          Not to sure what it is you are trying to achieve here, if you don't want a list that shows selected state you customise the renderer's behaviour, it doesn't make sense to have selection color overriden by rollover (if you look at the default item renderer source you can see how rollover color is selected).

           

          If you need a special case list there is no reason that you can't add your own states and logic just as long as the item renderer is written to give the desired display appearance.

           

           

          David.

          • 2. Re: Spark List states
            Peter deHaan Level 4

            @franto,

             

            If you want to disable selection altogether, you could probably get away with listening for the cancelling event and just kill the event right there so the selection is canceled.

            <?xml version="1.0" encoding="utf-8"?>
            <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                           xmlns:s="library://ns.adobe.com/flex/spark"
                           xmlns:mx="library://ns.adobe.com/flex/mx">
               
                <s:Label text="{lst.selectedIndex}" />
                <s:List id="lst" changing="event.preventDefault();" horizontalCenter="0" verticalCenter="0">
                    <s:layout>
                        <s:VerticalLayout horizontalAlign="justify" gap="0" requestedRowCount="5" />
                    </s:layout>
                    <s:dataProvider>
                        <s:ArrayList source="[The,Quick,Brown,Fox,Jumps,Over,The,Lazy,Dog]" />
                    </s:dataProvider>
                </s:List>
               
            </s:Application>


             

             

            If you still want s:List selection but not the highlight, I think you'd have to go the custom item renderer route. This was a pretty quick attempt at removing the selection highlighting, but it may work for you:

             

            <?xml version="1.0" encoding="utf-8"?>
            <s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
                            xmlns:s="library://ns.adobe.com/flex/spark"
                            xmlns:mx="library://ns.adobe.com/flex/mx"
                            autoDrawBackground="false">
               
                <s:states>
                    <s:State name="normal" />
                    <s:State name="hovered" />
                </s:states>
               
                <s:Rect width="100%" height="100%" includeIn="hovered">
                    <s:fill>
                        <s:SolidColor color="haloBlue" />
                    </s:fill>
                </s:Rect>
               
                <s:Label text="{data}" left="5" right="5" top="5" bottom="5" />
               
            </s:ItemRenderer>

             

            Note: Using the custom item renderer approach, the list is still selectable and responds to keyboard navigation and still sets the selectedIndex, etc. The only thing I unhooked was the select item's background fill.

             

            Peter

            • 3. Re: Spark List states
              franto kormanak Level 1

              Thanks Peter, that was exactly, wash I was looking for event.preventDefault() for changing event. But maybe selectionEnabled property for list would be better, but for sure, solution is working correctly.

               

              Thank you

              • 4. Re: Spark List states
                Peter deHaan Level 4

                @franto,

                 

                True, feel free to file an enhancement request to s:List at http://bugs.adobe.com/flex/ and we can consider it for a future release of the Flex SDK (too late for Flex 4.0, I'm afraid).

                 

                Peter

                (I also added both the examples above to http://blog.flexexamples.com/, thanks for the suggestion!)