安卓:两个不同的事件进行单一的水龙头和长期preSS /双击? [英] Android: Two different events for single tap and long press/double tap?

查看:188
本文介绍了安卓:两个不同的事件进行单一的水龙头和长期preSS /双击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想开发一个功能,一个项目一个水龙头将调用的意图,去到另一个活动,而该项目的长期preSS或双击做别的事情,比如让您编辑文本。

到目前为止,我只能够得到既发生在同一时间,但不单独。有没有人有什么想法?

 公共布尔的onTouchEvent(MotionEvent E){
    返回gestureScanner.onTouchEvent(E);
}


公共布尔onSingleTapConfirmed(MotionEvent E){
    意图I =新的意图(的getContext(),SecondClass.class);
    。的getContext()startActivity(ⅰ);

    返回true;
}

公共布尔onFling(MotionEvent E1,E2 MotionEvent,浮velocityX,浮velocityY){返回false; }
公共无效onLong preSS(MotionEvent E){
    Toast.makeText(的getContext(),在这里编辑功能,Toast.LENGTH_SHORT).show();

}
 

解决方案

我设法解决这个问题。原来,所有我需要做的是改变返回false在onDown为返回true()方法。

 公共布尔的onTouchEvent(MotionEvent E){
    返回gestureScanner.onTouchEvent(E);
}

公共布尔onSingleTapConfirmed(MotionEvent E){

    意图I =新的意图(的getContext(),SecondClass.class);
    。的getContext()startActivity(ⅰ);

    返回true;
}

公共布尔onDown(MotionEvent E){返回true; }


公共无效onLong preSS(MotionEvent E){
    Toast.makeText(的getContext(),编辑功能,Toast.LENGTH_SHORT).show();

}
 

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();

}

解决方案

I have managed to solve the problem. It turns out all I needed to do is change "return false" to "return true" in the onDown() method.

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();

}

这篇关于安卓:两个不同的事件进行单一的水龙头和长期preSS /双击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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