能够长久$移动后活动部$ PSS触发? [英] Can LongPress trigger after move events?

查看:231
本文介绍了能够长久$移动后活动部$ PSS触发?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个简单的Andr​​oid应用程序,我的要求是,

I am working on a simple android app, my Requirement is,

一些移动事件(MotionEvent.ACTION_MOVE为true)在屏幕上后,如果用户停止移动几秒钟一些地方用了从屏幕上走的手指,则需要执行一些动作。

*我了解到,龙preSS是什么触发,如果用户不作任何举动向下事件被触发(MotionEvent.ACTION_DOWN)之后。*

*I learnt that LongPress is something which triggers when user doesn't make any move after the down event is triggered(MotionEvent.ACTION_DOWN).*

那么,有没有办法在屏幕上四处移动后触发隆preSS?

So is there any way to trigger LongPress after Moving around in the screen?

或者我应该创建自己的侦听器相同的功能??

Or should I create my own listener for the same functionality??

任何帮助是AP preciated。

Any help is appreciated.

感谢您。

推荐答案

想法是取消您在屏幕上移动手指定时器每次( MotionEvent .ACTION_MOVE )。当你停止了一段时间后动,说在3秒钟后,定时器code将得到执行,在其中你可以做长preSS任务。如果停止移动了一段时间,并重新开始经过时间(3秒)前移动,再次新定时器被设置等。希望它可以帮助你。

Idea is to cancel the timer everytime you move finger on screen(MotionEvent.ACTION_MOVE). When you stop moving after some time, say after 3 seconds, timer code will get executed, in which you can do long press task. If you stop moving for some time and again start moving before elapse time (3 sec), again new timer is set and so on. Hope it helps you.

timer = new Timer();

public boolean onTouchEvent(MotionEvent event) 
{
    switch(event.getAction()) 
    {
        case MotionEvent.ACTION_DOWN:
             break;

        case MotionEvent.ACTION_MOVE:
             timer.cancel();
             timer = null;
             timer = new Timer();
             timer.schedule(new TimerTask() 
             {                  
                @Override
                public void run() {
                    // do your long press task here
                }
             }, 3000);
             break;

        case MotionEvent.ACTION_UP:
             timer.cancel();
             timer = null;
             break;
    }
    return super.onTouchEvent(event);
}

这篇关于能够长久$移动后活动部$ PSS触发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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