Skip to main content
Participating Frequently
July 11, 2012
Question

Item does not display in correct position with TileLayout

  • July 11, 2012
  • 2 replies
  • 889 views

Please take a look at below coding. If I choose Frank and click button “age<5", the damn Frank stays still rather than the first column.

What else should I do after refreshing the data list?

Best Regards,

<?xml version="1.0" encoding="utf-8"?>

<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"

                                        xmlns:s="library://ns.adobe.com/flex/spark" title="HomeView">

 

          <fx:Script>

                    <![CDATA[

                              import mx.collections.Sort;

                              protected function button1_clickHandler(event:MouseEvent):void

                              {

                                        // TODO Auto-generated method stub

                                        list.filterFunction = f1;

                                        list.refresh();

                              }

 

                              protected function button2_clickHandler(event:MouseEvent):void

                              {

                                        // TODO Auto-generated method stub

                                        list.filterFunction = f2;

                                        list.refresh();

                              }

 

                              private function f1(item:Object):Boolean

                              {

                                        var i:int = int(item.age);

                                        return i<20;

                              }

 

                              private function f2(item:Object):Boolean

                              {

                                        var i:int = int(item.age);

                                        return i>5;

                              }

                    ]]>

          </fx:Script>

 

          <fx:Declarations>

                    <!-- Place non-visual elements (e.g., services, value objects) here -->

                    <s:ArrayCollection id="list">

                              <fx:Object name="April" age="1"  sex="male" />

                              <fx:Object name="Brown" age="2"  sex="male" />

                              <fx:Object name="Cindy" age="3"  sex="male" />

                              <fx:Object name="Daren" age="4"  sex="male" />

                              <fx:Object name="Emily" age="5"  sex="male" />

                              <fx:Object name="Frank" age="6"  sex="male" />

                              <fx:Object name="Green" age="7"  sex="male" />

                              <fx:Object name="Helen" age="8"  sex="male" />

                              <fx:Object name="Ice" age="9"  sex="male" />

                              <fx:Object name="Jack" age="10"  sex="male" />

                              <fx:Object name="Lance" age="11"  sex="male" />

                              <fx:Object name="Mary" age="12"  sex="male" />

                              <fx:Object name="Nancy" age="13"  sex="male" />

                              <fx:Object name="Opera" age="14"  sex="male" />

                              <fx:Object name="Quntas" age="15"  sex="male" />

                              <fx:Object name="Ray" age="16"  sex="male" />

                              <fx:Object name="Stone" age="17"  sex="male" />

                              <fx:Object name="Tom" age="18"  sex="male" />

                    </s:ArrayCollection>

          </fx:Declarations>

          <s:List x="69" y="57" width="320" height="320" dataProvider="{list}" itemRenderer="spark.components.LabelItemRenderer"

                                                  labelField="name">

                    <s:layout>

                              <s:TileLayout columnWidth="100" orientation="rows" requestedColumnCount="3"

                                                                                                    requestedRowCount="3" rowHeight="100"/>

                    </s:layout>

          </s:List>

          <s:Button x="63" y="9" label="age &lt; 20" click="button1_clickHandler(event)"/>

          <s:Button x="157" y="9" label="age &gt; 05" click="button2_clickHandler(event)"/>

</s:View>

This topic has been closed for replies.

2 replies

Inspiring
July 13, 2012

Hi,

It seems that is a problem with selectedIndex.

Try:

protected function button1_clickHandler(event:MouseEvent):void

{

    myList.selectedIndex = -1;

    list.filterFunction = f1;

    callLater(applySort);

}

protected function button2_clickHandler(event:MouseEvent):void

{

    myList.selectedIndex = -1;

    list.filterFunction = f2;

    callLater(applySort);

}

private function applySort():void

    list.refresh();

}

<s:List id="myList" x="69" y="57"...

Philippe

yancaoshiAuthor
Participating Frequently
July 13, 2012

Thanks for your reply though it doesn't work for this

I find it displays correctly if I click it again

There must be something wrong inside.

Anyway, it works too if I set dataprovider null and data again

yancaoshiAuthor
Participating Frequently
July 12, 2012

And, it happens to mobile project only. I cannot reproduce this in desktop prj.