Skip to content Skip to sidebar Skip to footer

Android Onlongclicklistener Not Firing On Mapview

I just registered an OnLongClickListener on my my MapView on an Android app I'm currently writing. For some reason however the onLongClick event doesn't fire. Here's what I've writ

Solution 1:

I ran into the same problem and there is a simple solution to your problem actually; it's because you're using the wrong type of listener.

You should use the OnMapLongClickListener() object from the OnMapLongClickListener interface.

Hopefully everything should work properly :) Please tell me if it works.

Solution 2:

I just ran into this problem. I tried the solution above, but it doesn't quite work 100% in that we want the long press action to fire, even if the user is still holding a finger down.

This is how I implemented a solution, using a handler and a delayed task - As a side note, I used a similar type implementation, but in reverse, to hide/show zoom controls on touch/etc..

privateHandlermHandler=newHandler();

privatefinalRunnablemTask=newRunnable() {
    @Overridepublicvoidrun() {
        // your code here
    }
};

@OverridepublicbooleanonTouchEvent(MotionEvent ev) {
    if (ev.getAction() == MotionEvent.ACTION_DOWN) {
        // record the start time, start the timer
        mEventStartTime = ev.getEventTime();
        mHandler.postDelayed(mTask, LONG_PRESS_TIME);
    } elseif (ev.getAction() == MotionEvent.ACTION_UP) {
        // record the end time, dont show if not long enough
        mEventEndTime = ev.getEventTime();
        if (mEventEndTime - mEventStartTime < LONG_PRESS_TIME) {
            mHandler.removeCallbacks(mTask);        
        }
    } else {
        // moving, panning, etc .. up to you whether you want to// count this as a long press - reset timing to start from now
                    mEventStartTime = ev.getEventTime();
        mHandler.removeCallbacks(mTask);
                    mHandler.postDelayed(mTask, LONG_PRESS_TIME);
    }

    returnsuper.onTouchEvent(ev);
}

Solution 3:

In the mean time I found the "solution" (or workaround, call it as you like) by myself. The way I worked through this issue is by using a GestureDetector and forwarding all touch events to that object by implementing an according OnGestureListener interface.

I've posted some code on my blog if anyone is interested: http://juristr.com/blog/2009/12/mapview-doesnt-fire-onlongclick-event/

Don't ask me why this didn't work by hooking up the OnLongClickListener directly on the MapView. If someone has an explanation let me know :)

UPDATE: My previously suggested solution using a GestureDetector posed some drawbacks. So I updated the blog post on my site.

Solution 4:

In WebView framework code performLongClick() is used to handle long press event, this is how Android copy Text Feature is implemented in Browser, that is why onLongClick is not been fired.

Post a Comment for "Android Onlongclicklistener Not Firing On Mapview"