长按 spark.components.list 项 [英] Long-Press spark.components.list Item

查看:21
本文介绍了长按 spark.components.list 项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道新版本的 flex 中是否有任何长按手势(比如在 Android 上)?

Does anyone know if there is any sort of Long-Press gesture (like on Android) in the new version of flex?

我希望在长按时使列表中的项目可编辑/可删除,但我真的希望我不必使用计时器等制作自己的长按手势.

I'm looking to make an item in a list editable/delete-able upon long-press, but I'm really hoping I wont have to make my own Long-Press gesture with a timer and whatnot.

如果没有内置,有没有人知道有关如何制作长按手势的任何资源/博客文章 - 或者,此外,如何制作可编辑列表?

If there is none built in, does anyone know of any resources/blog posts about how to make a Long-Press gesture - or, furthermore, how to make an Editable list?

推荐答案

flextras 回答了这个问题,我只是想跟进一个似乎有效的代码示例.现在,我只是做一个弹出窗口,询问您是否要从列表中删除该项目.

flextras answered it, and I just wanted to follow up with a code sample that seems to work. For now, I have it just do a popup asking if you want to delete the item from the list.

        private var deleteAlert:DeleteAlert = new DeleteAlert();
        private  var longPressTimer:Timer = new Timer(1500,1);

        protected function LoadChartView_viewActivateHandler(event:ViewNavigatorEvent):void {
            enableClick();
        }
        private function startLongPressMouse(event:MouseEvent):void {   
            startLongPressTimer();
            list.addEventListener(MouseEvent.MOUSE_MOVE, endLongPressMouse);
        }
        private function endLongPressMouse(event:MouseEvent):void {
            stopLongPressTimer();
            enableClick();
            list.removeEventListener(MouseEvent.MOUSE_MOVE, endLongPressMouse);
        }
        private function startLongPress(event:TouchEvent):void {
            startLongPressTimer();
            list.addEventListener(TouchEvent.TOUCH_MOVE, endLongPress);
        }
        private function endLongPress(event:TouchEvent):void {
            stopLongPressTimer();
            enableClick();
            list.removeEventListener(TouchEvent.TOUCH_MOVE, endLongPress);
        }
        private function startLongPressTimer():void {
            longPressTimer.start();
            longPressTimer.addEventListener(TimerEvent.TIMER_COMPLETE, longPressHandler);
        }
        protected function disableClick():void {
            trace("disable click");
            list.removeEventListener(MouseEvent.CLICK, regularClickHander);
        }
        public function enableClick():void {
            list.callLater(list.addEventListener, [MouseEvent.CLICK, regularClickHander]);
        }
        public function resetListSelection():void {
            list.selectedIndex = -1;
            list.validateDisplayList();
        }
        private function stopLongPressTimer():void{
            longPressTimer.stop();
            longPressTimer.reset()
        }
        public function longPressHandler(event:TimerEvent):void{
            disableClick();
            stopLongPressTimer();
            deleteAlert.addEventListener(PopUpEvent.CLOSE, popupClosedHandler);
            deleteAlert.open(this, false);
            PopUpManager.centerPopUp(deleteAlert);
        }
        public function popupClosedHandler(event:PopUpEvent):void{
            if (event.commit)data.removeItemAt(list.selectedIndex);
            callLater(resetListSelection);
        }

为了便于测试,我同时使用了鼠标和触摸事件:

I used both the mouse and touch events for easy testing:

<s:List id="list" top="0" bottom="0" left="0" right="0"
        dataProvider="{data}"
        touchBegin="startLongPress(event)" touchEnd="endLongPress(event)"
        mouseDown="startLongPressMouse(event)" mouseUp="endLongPressMouse(event)">

这篇关于长按 spark.components.list 项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆