如何在调用onDoubleTapEvent时(在gridview中)排除onTouch方法?

时间:2012-11-27 11:40:24

标签: android events double ontouchlistener tap

我需要在日历网格视图上使用触摸侦听器。它应该有一个onTouch方法来从日历中拖动数据,并使用onDoubleTapEvent来删除条目。我还实现了自定义类MyGestureListener,它扩展了SimpleOnGestureListener来执行此操作。代码的某些部分可以在下面看到:

calendarGridView.setOnTouchListener(new MyGestureListener(getApplicationContext()) {
    //Touch Listener on every gridcell
    public boolean onTouch(View v, MotionEvent event) {
    super.onTouch(v, event);
        ....
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN: {
            ....
            }
            case MotionEvent.ACTION_UP : {
            ....
            }
            case MotionEvent.ACTION_CANCEL: {
            ....
            }
        }
   //Save the data
   return true;
   }

   public boolean onDoubleTapEvent(MotionEvent event) {
   .... //delete the entry, save data
   return true;
   }

自定义手势监听器类:

public class MyGestureListener extends SimpleOnGestureListener implements OnTouchListener{

Context context;
GestureDetector gDetector;

public MyGestureListener(Context context) {
    super();

    if (gDetector == null) {
        gDetector = new GestureDetector(context, this);
    }
    this.context = context;
}

public MyGestureListener(Context context, GestureDetector gDetector) {

    if (gDetector == null) {
        gDetector = new GestureDetector(context, this);
    }
    this.context = context;
    this.gDetector = gDetector;
}

public boolean onTouch(View v, MotionEvent event) {

    return gDetector.onTouchEvent(event);
}

public GestureDetector getDetector() {

    return gDetector;
}

}

这里的问题是,当我双击日历单元格时,它会调用onDoubleTapEvent,还会调用onTouch方法(考虑ACTION_DOWN,ACTION_UP和ACTION_DOWN,ACTION_UP)。我该如何分开它们?

0 个答案:

没有答案