1
votes

I have a spark datagrid on a mobile application, I set the

interactionMode="touch"

and the dataGrid scrolling is good, I got some problems adding a selectionChange eventListener to it, because scrolling the dataGrid will automatically change the selection and instead simply scrolling it, the function binded will start...

How can I add the touch dalay before select the index, so if I scroll the grid the selection won't change, and it change only if I press the item without scrolling?

1

1 Answers

1
votes

I solved using a workaround....

Instead adding the selectionChange eventListener, I used the mouseUp and mouseDown to check the time between click and release, and if the release time is less than click plus some dalay, I return the selection otherwise not...

<s:DataGrid id="grigliaData"
   sortableColumns="false"
   rowHeight="100"
   interactionMode="touch"
   mouseDown="grigliaData_mouseDownHandler(event)"
   mouseUp="grigliaData_mouseUpHandler(event)"
   top="230" left="5" right="5" bottom="50"
   dataProvider="{listaEventi}" width="100%" height="100%"> 

  //AS Code 
        private var _lastClickEvent:int;
        protected function grigliaData_mouseDownHandler(event:MouseEvent):void
        {
            _lastClickEvent = getTimer();
        }

        protected function grigliaData_mouseUpHandler(event:MouseEvent):void
        {
            if (getTimer() < _lastClickEvent + 200) // 200 = Dalay
            {
                               // return selectedIndex
            }
        }

EDIT: I also added the check on mouseX and mouseY position, now the grid dispatch the selectionChange if the time before release and the change of position is less that the default dalay (time/pixel)...