开发者

How to create a Context Menu on a MapView?

开发者 https://www.devze.com 2023-02-04 00:43 出处:网络
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 Crea开发者_运维百科ti

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 Crea开发者_运维百科ting 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);
    }
}


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消