我正在使用 mapsforge 库在我的应用程序中使用地图。我需要启动上下文菜单并返回地图坐标。这是我尝试过的。在我的布局中,我在地图视图下方设置了一个隐藏按钮,用于侦听长按。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<org.mapsforge.map.android.view.MapView
android:id="@+id/offlinemapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<Button
android:id="@+id/mapview_btn_offline"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
然后我为上下文菜单注册这个按钮并膨胀上下文菜单。
mapb = (Button) findViewById(R.id.mapview_btn_offline);
registerForContextMenu(mapb);
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.map_menu, menu);
}
但是当我运行该应用程序时,即使在长按后上下文菜单也不会出现。关于如何使它工作的任何想法?