android action bar onNavigationItemSelected

后端 未结 5 2144
死守一世寂寞
死守一世寂寞 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:24

    The android system will call onNavigationItemSelected(0, 0) after the activity is setup. (Which means later than onResume()).

    As other guys mentioned, you'd better not do any hack like ignore first call, otherwise the android system won't call onNavigationItemSelected() again when you select the first index. (The system thought the first item is already selected)

    My solution is call actionbar.setSelectedNavigationItem(the real item# you want) after you setup the actionbar. Then the system will call onNavigationItemSelected() twice. First onNavigationItemSelected(0, 0) and then the onNavigationItemSelected(the real item#).

提交回复
热议问题