Question

I am using mapsforge library to use maps in my app. I need to fire up a context menu and return the map coordinates. Here's what i have tried. In my layout i have a hidden button set up below the mapview that listens for longpress.

<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>

Then i am registering this button for context menu and inflate the context menu.

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

But when i run the app, even after the longpress the context menu does not show up. Any ideas on how to get this working ?

Was it helpful?

Solution

Actually mapview class is an extended class from ViewGroup. you should do following:

1.Override the OnTouchEvent in mapsforge. MotionEvent gets you some actions. 2.Define a timer to hold the time between touch_down and touch_up or cancel. 3.It's up to you to how implement the spare parts...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top