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 written so far:

public class FriendMapActivity extends MapActivity implements OnLongClickListener {
    private static final int CENTER_MAP = Menu.FIRST;
    private MapView mapView;
    private MapController mapController;
    private boolean doCenterMap = true;

    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {
        this.mapView = (MapView) findViewById(;
        this.mapController = mapView.getController();

        mapView.setOnLongClickListener(new OnLongClickListener() {
            public boolean onLongClick(View v) {
                //NEVER FIRES!!
                return false;


    public boolean onKeyDown(int keyCode, KeyEvent event) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_3:
        case KeyEvent.KEYCODE_1:
        return super.onKeyDown(keyCode, event);

    public boolean dispatchTouchEvent(MotionEvent ev) {
        int actionType = ev.getAction();
        switch (actionType) {
        case MotionEvent.ACTION_MOVE:
            doCenterMap = false;

        return super.dispatchTouchEvent(ev);


May overlays which I’m adding cause the problem?? Any suggestions?


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:

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 🙂

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

Leave a Reply

Your email address will not be published. Required fields are marked *