android - onOptionsItemSelected is never called -


i'm following tutorial, , i'm writing simple activity.

...

update: after tips i've edited app, method onoptionsitemselected() still not called when select item popup menu. popup menu inflated when user click on item action bar.

the activity:

public class map extends appcompatactivity implements     googlemap.onmaplongclicklistener, googlemap.onmarkerclicklistener,     googlemap.onmapclicklistener, onmapreadycallback,     resourcestate.onresourcestatechangelistener {  ...  @override public boolean oncreateoptionsmenu(menu menu) {     map.menu = menu;     getmenuinflater().inflate(r.menu.map_menu, menu);     return super.oncreateoptionsmenu(menu); }  @override public boolean onoptionsitemselected(menuitem item) {     switch (item.getitemid()) {          ...          case r.id.menu_item_map_type:             // here show popup             popupmenu popup = new popupmenu(this, findviewbyid(r.id.menu_item_map_type));             popup.getmenuinflater().inflate(r.menu.map_popup, popup.getmenu());             popup.show();             break;          case r.id.menu_item_satellite:             // here method onoptionsitemselected not directly called             break;          case r.id.menu_item_street:             // here method onoptionsitemselected not directly called             break;     }      return super.onoptionsitemselected(item); }  public void callonoptionsitemselected(menuitem item) {     onoptionsitemselected(item); }  ... 

}

the primary menu:

<?xml version="1.0" encoding="utf-8"?> <menu     xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto" >      <item android:id="@+id/menu_item_send"           android:icon="@drawable/ic_send"           android:title="send"           app:showasaction="ifroom"/>      <item android:id="@+id/menu_item_location"           android:icon="@drawable/ic_location_on"           android:title="my position"           app:showasaction="ifroom"/>      <item android:id="@+id/menu_item_map_type"           android:icon="@drawable/ic_map"           android:title="map view"           app:showasaction="ifroom"/>  </menu> 

the popup menu:

<?xml version="1.0" encoding="utf-8"?> <menu     xmlns:android="http://schemas.android.com/apk/res/android"     android:orientation="vertical" >      <item         android:id="@+id/menu_item_satellite"         android:title="satellite"         android:checkable="true"         android:onclick="callonoptionsitemselected"/>      <item         android:id="@+id/menu_item_street"         android:title="street"         android:checkable="true"         android:onclick="callonoptionsitemselected" />  </menu> 

my temporary solution defining method callonoptionsitemselected(), wich calls method onoptionsitemselected(). way, i'd know i'm missing.

(another issue related popup method setchecked() of class menuitem, not working.)

i don't know why add

android:id="@+id/layout_map_popup" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical"  

in menu.xml file


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -