android action bar onNavigationItemSelected

后端 未结 5 2138
死守一世寂寞
死守一世寂寞 2020-12-05 20:01

I\'m developing for android 3+

In my action bar i have a drop-down list(see how to hide/unhide the actionbar list on android 3? for the dropdown i intend). The probl

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-05 20:37

    Method onNavigationItemSelected(int itemPosition, long itemId) will be called anyway by the action bar.

    What you may want to do is to tell action bar what itemPosition it should pass to the method on the first call. (In other words, to tell action bar what navigation item should be set after activity is created). Here is the code:

    mActionBarMenuSpinnerAdapter = ...;
    mActionBar = getActionBar();
    mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
    mActionBar.setListNavigationCallbacks(mActionBarMenuSpinnerAdapter, this);
    mActionBar.setSelectedNavigationItem(###your_default_navigation_item_here###);
    

    After doing this you can solve your problem by applying changes in the onNavigationItemSelected(int itemPosition, long itemId) if only itemPosition is different.

提交回复
热议问题