Jay Gridley
Jay Gridley

Reputation: 723

Long click on InfoWindow of GoogleMap on Android

I am using custom InfoWindowsAdapter for GoogleMap on Android. My problem is, that I am not able to attach onLongClickListener on that custom info window. GoogleMap class has only OnClickListener, but OnLongClickListener is missing from API.

I have tried to attach OnLongClickListener on my custom view, but this Listener is not called.

private class EventInfoWindowAdapter implements InfoWindowAdapter {    
    public View getInfoWindow(Marker marker) {

            //mWindow is clicable (I do set it in layout XML)
        mWindow = getLayoutInflater().inflate(R.layout.event_info_window, null);

        mWindow.setOnLongClickListener(new LinearLayout.OnLongClickListener() {

            @Override
            public boolean onLongClick(View view) { //THIS ONE IS NOT CALLED

                Log.d("LONG", "CLICKED");

                contextMode = startActionMode(actionModeCallback);

                return true;
            }
        });

        return mWindow;
    }
}

//in onCreate(...) method

mMap = ((MapView) findViewById(R.id.map)).getMap();
mMap.setInfoWindowAdapter(new EventInfoWindowAdapter());

Any suggestions how to make it works?

Upvotes: 3

Views: 3219

Answers (1)

Artemiy
Artemiy

Reputation: 482

The listener won't work because what you're displaying as an InfoWindow overlay isn't a View - it's a snapshot of a View, pretty much a picture for most means and purposes. I had similar troubles, so these answers might help you:

Adding a button to a custom InfoWindowAdapter view that can register clicks

Upvotes: 3

Related Questions