How to create a context menu in MapView?

I would like to have a context menu on mine MapViewand let the user choose between a map or satellite photo in the background. I tried to create a context menu by doing "Create a menu" , but it does not work for me.

The application works, but the context menu is not displayed. How to create a context menu on MapView?

In mine onCreate(), I have this code:

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

And I redefined 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);
    }
}
+3
source share
1 answer

, MapView, , - , . .

+2

Source: https://habr.com/ru/post/1785418/


All Articles