i want to add some options when a user presses the menu button, i have tried the following but nothing seems to happen when i run the app and press the menu button:
the menu xml file
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/Map_view"
android:title="@string/Map_view"
android:icon="@drawable/satellite_view">
<menu>
<group android:checkableBehavior="single"
android:id="@+id/menu_items">
<item android:id="@+id/satellite_view"
android:icon="@drawable/satellite_view"
android:title="@string/satellite_view"/>
<item android:id="@+id/street_view"
android:icon="@drawable/street_view"
android:title="@string/street_view"/>
</group>
</menu>
</item>
</menu>
the MapAcitivity class
package com.example.MyMapActivity;
import java.util.List;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;
public class MyMapActivity extends MapActivity {
private MapView mapview;
private MapController mapcontroller;
private GeoPoint gp;
//creating a class to for OverLays
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//setting the zoom controls
mapview = (MapView)findViewById(R.id.mapview);
mapview.setBuiltInZoomControls(true);
mapview.setSatellite(true);
List<Overlay>mapOverlays = mapview.getOverlays();
// pass the drawable to instance of the OVerlay class.
Drawable drawable = this.getResources().getDrawable(R.drawable.marker);
MyOverlay overlay = new MyOverlay(drawable,this);
//setting a GeoPoint
mapcontroller=mapview.getController();
String coordinates[] = {"23.68855","86.97455"};
double lat = Double.parseDouble(coordinates[0]);
double longi = Double.parseDouble(coordinates[1]);
gp = new GeoPoint((int)(lat*1E6), (int)(longi*1E6));
OverlayItem overlayitem = new OverlayItem(gp, "Hello ", "I'm in Asansol");
GeoPoint point2 = new GeoPoint(35410000, 139460000);
OverlayItem overlayitem2 = new OverlayItem(point2, "Sekai, konichiwa!", "I'm in Japan!");
overlay.addOverlay(overlayitem); // call this method for each overlayitem
overlay.addOverlay(overlayitem2);
mapOverlays.add(overlay);
}
// to inflate the menu defined in the map_menu xml file
public boolean OnCreateOptionsMenu(Menu menu)
{
MenuInflater inflator = getMenuInflater();
inflator.inflate(R.menu.map_menu, menu);
return true;
}
public boolean OnOptionsItemSelected(MenuItem item)
{
switch(item.getItemId())
{
case R.id.satellite_view:
if(item.isChecked())
mapview.setSatellite(true);
return true;
case R.id.street_view:
if(item.isChecked())
mapview.setStreetView(true);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
// this method must return true if your app returns driving directions , else return false
return false;
}
}