Gid*_*zer 5 events android tap listener
我正在尝试开发一个功能,其中单击一个项目将调用Intent转到另一个Activity,并且长按或双击该项目会执行其他操作,例如允许您编辑文本.
到目前为止,我只能在同一时间发生这两种情况,但不能单独发生.有没有人有任何想法?
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();
}
Run Code Online (Sandbox Code Playgroud)
我设法解决了这个问题.原来,所有我需要做的是改变返回值false以true在onDown()处理程序.
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();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7042 次 |
| 最近记录: |