Nick
Nick

Reputation: 1733

GridView problems with touchlisteners

I'm trying to create a custom GridView but i'm having troubles with the touch listeners.

What i want to do:

Here's where i'm having trouble:
I'm implementing GestureDetector.OnGestureListener for the longpress functions, because for some reason using the gridview.setOnItemLongClickListener() isn't working when overriding the onTouchEvent() of the GridView itself (Which i need for the dragging part). So everything is fine at this point. Now i only need to know when the longpress is finished. So i though: "Well this shouldn't be hard." I couldn't have be more wrong. I've fiddled around for quite some time with this and it looks like using different touch events isn't helping me :/
When stepping through the onTouchEvent() i noticed that only 1 action is given: MotionEvent.ACTION_DOWN. So what am i doing wrong? i need the MotionEvent.ACTION_UP...

Upvotes: 1

Views: 1665

Answers (1)

Nick
Nick

Reputation: 1733

Found the culprit:

i was doing something like this

@Override
public boolean onTouchEvent(MotionEvent event) {

    // Give everything to the gesture detector
    boolean retValue = gestureDetector.onTouchEvent(event);

    switch (event.getAction()) {
        case MotionEvent.ACTION_MOVE :
            onMove();
            break;
        case MotionEvent.ACTION_UP :
            onUp();
            break;
        case MotionEvent.ACTION_CANCEL:
            onCancel();
            break;
    }
    return retValue;
}  

i think retValue was always returning false so no other events were triggered.
this fixed the issue:

@Override
public boolean onTouchEvent(MotionEvent event) {

    // Give everything to the gesture detector
    gestureDetector.onTouchEvent(event);

    switch (event.getAction()) {
        case MotionEvent.ACTION_MOVE :
            onMove();
            break;
        case MotionEvent.ACTION_UP :
            onUp();
            break;
        case MotionEvent.ACTION_CANCEL:
            onCancel();
            break;
    }
    return true;
}

Upvotes: 2

Related Questions