Actionbar dropdown click event

2019-03-25 13:54发布

问题:

I have dropdown list in actionbar as navigation list. Using ActionBar.OnNavigationListener and onNavigationItemSelected to detect when user has clicked on item in actionbar dropdown navigation list and that works fine.

However, onNavigationItemSelected is not called if user has clicked on the same item as the one which is currently selected in dropdown list! (I need this exact functionality behavior for app to work properly)

So is there any way to detect click on any part of the dropdown list in actionbar?

Is there a way to somehow reference dropdown view in actionbar, and then set onclicklistner on that dropdown object in actionbar. Like when we use dropdown list in standard layout?

回答1:

The problem here is the same as with any other Spinner. The workariund for this is clearly described here: Spinner : onItemSelected not called when selected item remains the same

However for the ActionBar the solution can be a bit tricky (except for when you are using the ActionBarSherlock and can explicitly mess with its code)