Android:两次不同的事件单击并长按/双击? [英] Android: Two different events for single tap and long press/double tap?

查看:532
本文介绍了Android:两次不同的事件单击并长按/双击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试开发一个功能,只需点击一个项目即可调用Intent进入另一个Activity,长按或双击该项目会执行其他操作,例如允许您编辑文本。

I am trying to develop a feature where a single tap of an item will call an Intent to go to another Activity, and a long press OR double tap of the item does something else, such as allow you to edit the text.

到目前为止,我只能同时发生两个事件,而不是单独发生。有没有人有任何想法?

So far I am only able to get both to happen at the same time but not individually. Does anyone have any ideas?

public boolean onTouchEvent(MotionEvent e) {
    return gestureScanner.onTouchEvent(e);
}


public boolean onSingleTapConfirmed(MotionEvent e) { 
    Intent i = new Intent(getContext(), SecondClass.class);
    getContext().startActivity(i);

    return true; 
}

public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return false; }
public void onLongPress(MotionEvent e) {
    Toast.makeText(getContext(), "Edit feature here", Toast.LENGTH_SHORT).show();

}


推荐答案

我管理解决问题。原来,我需要做的是将 false 中的返回值更改为 true > onDown()处理程序。

I managed to solve the problem. It turned out all I needed to do is change the return value from false to true in the onDown() handler.

public boolean onTouchEvent(MotionEvent e) {
    return gestureScanner.onTouchEvent(e);
}

public boolean onSingleTapConfirmed(MotionEvent e) { 

    Intent i = new Intent(getContext(), SecondClass.class);
    getContext().startActivity(i);

    return true; 
}

public boolean onDown(MotionEvent e) { return true; }


public void onLongPress(MotionEvent e) {
    Toast.makeText(getContext(), "Edit Feature", Toast.LENGTH_SHORT).show();

}

这篇关于Android:两次不同的事件单击并长按/双击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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