我按事件onTouch移动项目
但我只想在LongClick和移动时移动Item。
如何在ListView的进程事件OnItemLongClick中调用事件onTouchEvent?
答案 0 :(得分:0)
//Imports
import android.view.GestureDetector.OnGestureListener;
import android.view.GestureDetector;
//Constructor
GestureDetector gestureDetector = new GestureDetector(getContext(), gestureListener);
//Listener
private final OnGestureListener gestureListener = new OnGestureListener() {
@Override
public boolean onDown(MotionEvent e) {
return true;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,float velocityY) {
return false;
}
@Override
public void onLongPress(MotionEvent e) {
//DO YOUR STUFF IN HERE
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2,float distanceX, float distanceY) {
return false;
}
@Override
public void onShowPress(MotionEvent e) {
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
return true;
}
};
//Touch
@Override
public boolean onTouchEvent(MotionEvent ev) {
boolean result = gestureDetector.onTouchEvent(ev);
return result;
}