【问题标题】:How to create a Context Menu on a MapView?如何在 MapView 上创建上下文菜单?
【发布时间】:2011-01-14 11:33:42
【问题描述】:

我想在我的MapView 上有一个上下文菜单,让用户在背景中选择地图或卫星照片。我尝试通过关注Creating Menus 创建上下文菜单,但它对我不起作用。

应用程序可以运行,但没有显示上下文菜单。如何在我的 MapView 上创建上下文菜单?

在我的onCreate() 我有这个代码:

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

而且我已经重写了一些方法:

@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);
    }
}

【问题讨论】:

    标签: android android-mapview contextmenu


    【解决方案1】:

    似乎正常的长按处理不适用于MapView,这可能是由于它处理触摸事件的方式。 Theresome workarounds 如果你真的需要这个功能的话。

    【讨论】:

      猜你喜欢
      • 2014-07-27
      • 2022-01-03
      • 2011-09-30
      • 1970-01-01
      • 2011-06-21
      • 1970-01-01
      • 1970-01-01
      • 2011-04-08
      • 2014-12-15
      相关资源
      最近更新 更多