When you say it doesn't work, we really need more info to try and help you! Does it crash, does it stay on Street/Sat View or just normal map etc, try to give more info and if it crashed post a copy of the logcat.
I think all you are missing is the line:
(EDIT: I just tried it without calling invalidate and it works so it must be the menu button ID's)
mapView.invalidate();
You need to call this in order for the mapView to refresh itself, so call it every time you change the mapView settings.
If that doesnt work then it may be your id's for the buttons arent recognised in your switch so try setting up your menu as an xml file int res/menu/ like:
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:title="Street View" android:numericShortcut="1" android:id="@+id/mapStreet" ></item>
<item android:title="Sat View" android:numericShortcut="2" android:id="@+id/mapSat"></item>
</menu>
Then modify your code to:
public boolean onCreateOptionsMenu(Menu menu){
super.onCreateOptionsMenu(menu);
MenuInflater oMenu = getMenuInflater();
oMenu.inflate(R.menu.mapsmenu, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item){
switch(item.getItemId()){
case R.id.mapStreet:
mapView.setStreetView(true);
mapView.setSatellite(false);
mapView.invalidate();
return true;
case R.id.mapSat:
mapView.setSatellite(true);
mapView.setStreetView(false);
mapView.invalidate();
return true;
}
return false;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…