Question

A the moment I have this options menu

Currently working

I would like to add to options at the bottom below hybrid map. Here is my code. I have added in where I would like the two other menu options to be but they don't work.

@Override
public boolean onOptionsItemSelected(MenuItem item)
{
    super.onOptionsItemSelected(item);

    switch(item.getItemId())
    {
    case R.id.normal_map:
        mapType=GoogleMap.MAP_TYPE_NORMAL;
        break;

    case R.id.satellite_map:
        mapType=GoogleMap.MAP_TYPE_SATELLITE;
        break;

    case R.id.terrain_map:
        mapType=GoogleMap.MAP_TYPE_TERRAIN;
        break;

    case R.id.hybrid_map:
        mapType=GoogleMap.MAP_TYPE_HYBRID;
        break;

    case R.id.games2014:
        games2014=true;
        break;

    case R.id.games_past:
        games2014=false;
        break;
    }

    googleMap.setMapType(mapType);
    return true;
}

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/map_types"
    android:title="Menu"
    android:showAsAction="always">
    <menu>
        <item android:id="@+id/normal_map"
            android:title="Mormal map"/>
        <item android:id="@+id/satellite_map"
            android:title="Satellite map"/>
        <item android:id="@+id/terrain_map"
            android:title="Terrain map"/>
        <item android:id="@+id/hybrid_map"
            android:title="Hybrid map"/>
        <Item android:id="@+id/games2014"
            android:title="2014 Games"/>
        <Item android:id="@+id/games_past"
            android:title="Previous Games"/>
    </menu>     
</item>   

Was it helpful?

Solution 2

<Item android:id="@+id/games2014"
   android:title="2014 Games"/>
<Item android:id="@+id/games_past"
   android:title="Previous Games"/>

Your "I" in "Item" is capital. It should be a lowercase "i" - "item"

OTHER TIPS

In your item you declared it as Item which would cause it not to add

@Override
public boolean onOptionsItemSelected(MenuItem item)
{
    super.onOptionsItemSelected(item);

    switch(item.getItemId())
    {
    case R.id.normal_map:
        mapType=GoogleMap.MAP_TYPE_NORMAL;
        break;

    case R.id.satellite_map:
        mapType=GoogleMap.MAP_TYPE_SATELLITE;
        break;

    case R.id.terrain_map:
        mapType=GoogleMap.MAP_TYPE_TERRAIN;
        break;

    case R.id.hybrid_map:
        mapType=GoogleMap.MAP_TYPE_HYBRID;
        break;

    case R.id.games2014:
        games2014=true;
        break;

    case R.id.games_past:
        games2014=false;
        break;
    }

    googleMap.setMapType(mapType);
    return true;
}

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/map_types"
    android:title="Menu"
    android:showAsAction="always">
    <menu>
        <item android:id="@+id/normal_map"
            android:title="Mormal map"/>
        <item android:id="@+id/satellite_map"
            android:title="Satellite map"/>
        <item android:id="@+id/terrain_map"
            android:title="Terrain map"/>
        <item android:id="@+id/hybrid_map"
            android:title="Hybrid map"/>
        <item android:id="@+id/games2014"
            android:title="2014 Games"/>
        <item android:id="@+id/games_past"
            android:title="Previous Games"/>
    </menu>     
</item> 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top