3

I would like to have a Context Menu on my MapView and let the user choose between a map or a satellite photo in the background. I have tried to create a Context Menu by following Creating Menus but it doesn't work for me.

The application works but no Context Menu is shown. How can I create a Context Menu on my MapView?

In my onCreate() I have this code:

    MapView mapView = (MapView) findViewById(R.id.mapview);
    registerForContextMenu(mapView);

And I have overrided some methods:

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo info) {
    super.onCreateContextMenu(menu, v, info);
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.context_menu, menu);
}

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    switch (item.getItemId()) {
    case R.id.map_view_item: 
        return true;
    case R.id.satellite_item: 
        return true;
    default: return super.onContextItemSelected(item);
    }
}
Jonas
  • 121,568
  • 97
  • 310
  • 388

1 Answers1

2

It appears that normal long-click processing does not work well with MapView, perhaps due to the way it handles touch events. There are some workarounds if you really need the functionality.

Community
  • 1
  • 1
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491