1
我正在使用手勢來捕獲觸摸事件,但它在我長按時觸發兩個事件。 當我按下按鈕時,如何禁用onDown事件? 這是我的代碼。Android手勢檢測器onLongPress和onDown
final GestureDetector gestureDetector = new GestureDetector(
new GestureDetector.SimpleOnGestureListener() {
public void onLongPress(MotionEvent e) {
Toast.makeText(mContext,
"long" + position + counter++,
Toast.LENGTH_SHORT).show();
}
public boolean onDown(MotionEvent e) {
Toast.makeText(mContext,
"touch" + position + counter++,
Toast.LENGTH_SHORT).show();
return true;
}
});
category.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return gestureDetector.onTouchEvent(event);
}
});