Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/178.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在onTouch()中获取单次点击确认事件?_Android_Ontouchlistener - Fatal编程技术网

Android 如何在onTouch()中获取单次点击确认事件?

Android 如何在onTouch()中获取单次点击确认事件?,android,ontouchlistener,Android,Ontouchlistener,实际上,我想在onTouch方法中获取singletapconfixed()事件。我们都知道,我们可以使用gesturedector类来实现这个目的,但我想知道如何使用onTouch 我不想调用手势检测器#ontochevent我想手动检测 下面的代码用于双击,但如何在此代码中获得SingleTapConfirmation DoubleTap的代码: imageView.setOnTouchListener(new View.OnTouchListener() { @Ove

实际上,我想在onTouch方法中获取
singletapconfixed()
事件。我们都知道,我们可以使用
gesturedector
类来实现这个目的,但我想知道如何使用
onTouch

我不想调用
手势检测器#ontochevent
我想手动检测

下面的代码用于双击,但如何在此代码中获得SingleTapConfirmation

DoubleTap的代码:

imageView.setOnTouchListener(new View.OnTouchListener() {
           @Override
           public boolean onTouch(View view, MotionEvent event) {
               switch(event.getAction() & MotionEvent.ACTION_MASK)
               {
                   case MotionEvent.ACTION_DOWN:
                       startTime = System.currentTimeMillis();
                       clickCount++;
                       break;
                   case MotionEvent.ACTION_UP:
                       long time = System.currentTimeMillis() - startTime;
                       duration=  duration + time;
                       if(clickCount == 2)
                       {
                           if(duration<= MAX_DURATION)
                           {
                               Toast.makeText(imageView.getContext(), "double tap",Toast.LENGTH_LONG).show();
                           }
                           clickCount = 0;
                           duration = 0;
                           break;
                       }
               }
               return true;
           }
       });
imageView.setOnTouchListener(新视图.OnTouchListener(){
@凌驾
公共布尔onTouch(视图、运动事件){
开关(event.getAction()&MotionEvent.ACTION\u掩码)
{
case MotionEvent.ACTION\u DOWN:
startTime=System.currentTimeMillis();
点击计数++;
打破
case MotionEvent.ACTION\u UP:
长时间=System.currentTimeMillis()-startTime;
持续时间=持续时间+时间;
如果(单击计数=2)
{
如果(持续时间试试这个

 imageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

           startTime = System.currentTimeMillis();
                   clickCount++;

        }
    });
OnTouchListner返回falsh,因此禁止触摸事件

imageView.setOnTouchListener(new View.OnTouchListener() {
       @Override
       public boolean onTouch(View view, MotionEvent event) {
           switch(event.getAction() & MotionEvent.ACTION_MASK)
           {

               case MotionEvent.ACTION_UP:
                   long time = System.currentTimeMillis() - startTime;
                   duration=  duration + time;
                   if(clickCount == 2)
                   {
                       if(duration<= MAX_DURATION)
                       {
                           Toast.makeText(imageView.getContext(), "double 
                           tap",Toast.LENGTH_LONG).show();
                       }
                       clickCount = 0;
                       duration = 0;
                       break;
                   }
           }
           return false;
       }
   });
imageView.setOnTouchListener(新视图.OnTouchListener(){
@凌驾
公共布尔onTouch(视图、运动事件){
开关(event.getAction()&MotionEvent.ACTION\u掩码)
{
case MotionEvent.ACTION\u UP:
长时间=System.currentTimeMillis()-startTime;
持续时间=持续时间+时间;
如果(单击计数=2)
{

如果(持续时间使用手势检测与onTouch listener,如下所示即可

final GestureDetector gestureDetector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() {
    @Override
    public boolean onSingleTapConfirmed(MotionEvent e) {
     //do something
        return true;
    }

    @Override
    public void onLongPress(MotionEvent e) {
        super.onLongPress(e);
    }

    @Override
    public boolean onDoubleTap(MotionEvent e) {
        return super.onDoubleTap(e);
    }
});
并使用手势检测器作为

 viewToTouch.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {

        return gestureDetector.onTouchEvent(event);
    }
});

只需在
onTouch
内部调用
GestureDetector#onTouchEvent
method@pskink不,先生,我想手动检测?你是什么意思?你认为
gesturedector
检查单点“非手动”吗?你到底想实现什么?检查是否单击一次或什么?@pskink先生,请检查我编辑的问题,因为我们可以在onTouch中检测到双击。如何使用SingleTapConfirmated执行此操作。手动意味着我想增加SingleTapConfirmated方法的持续时间请参见
GestureDetector
源文件并检查
双击时间OUUT
双点击时间
不,先生,不允许双点击事件发生。只允许单点击事件发生happening@pskink先生,我只是个初学者,你能帮我吗that@user8027365在TouchListnersir上使返回值为false您能帮我增加SingleTapConfirm()吗事件的持续时间。我需要增加它的持续时间,因为我想同时使用SingleTapConfirm和doubleTap,但在某些情况下,SingleTapConfirm被称为First增加SingleTapConfirm()的意思是什么我指的是SingleTapConfirm()的持续时间 event@user8027365那么,您是否检查了双击超时和双击最小时间?您是否看到
gesturedector
源代码?@user8027365刚刚设置了您想要的值(以毫秒为单位)第227-228行