Note that there are some explanatory texts on larger screens.

plurals
  1. POContext menu on a MapView, or other solutions
    primarykey
    data
    text
    <p>I need to implement in my application a context menu on a MapView, which takes the coordinates of the selected long clicked point and show a set of option. I tried to register the MapActivity for context menu and then overriding the oncreatecontextmenu method, but the longclick event seems not to fire. (e.g. I put some log in the oncreatecontextmenu method which never show on ddms)</p> <p>I searched on the web and in the Android documentation but I have found nothing satisfying. So, is it really impossible to create a contextmenu on a MapView? If so, is there a way to implement something similar? I'm posting the (simple) code:</p> <pre><code>public class ChoosePosition extends MapActivity { MapView mappa; MapController mapCtr; LocationManager locManager; LocationListener locLstn; Location myLastLoc; String locProvider; double mylat, mylongi; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.chooseposition); locManager = (LocationManager)getSystemService(LOCATION_SERVICE); locLstn = new MyLocationListener(); locManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 2000, 10, locLstn); mappa = (MapView) findViewById(R.id.map2); mappa.setLongClickable(true); mapCtr = mappa.getController(); // attiviamo lo zoom integrato mappa.setBuiltInZoomControls(true); // getting last known location myLastLoc = locManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); GeoPoint point; if (myLastLoc == null) { mylat = myLastLoc.getLatitude(); mylongi = myLastLoc.getLongitude(); // trasformiamo l'ultima posizione in un GeoPoint point= new GeoPoint((int) (myLastLoc.getLatitude() * 1E6), (int) (myLastLoc.getLongitude() * 1E6)); } // setting center and zoom mapCtr.setCenter(point); mapCtr.setZoom(17); // adding an overlay MyLocationOverlay myLocationOverlay = new MyLocationOverlay(); mappa.getOverlays().add(myLocationOverlay); registerForContextMenu(mappa); } @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { Log.i("MYINFO", "I'm in"); menu.add(Menu.NONE, 0, Menu.NONE, "First option"); } @Override public boolean onContextItemSelected(MenuItem item) { return true; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload