Search code examples
android-actionbar-compat

Android OnNavigationListener not being called


I am using ActionBarCompat to create an action bar. I can display the dropdown navigation list in it with an ArrayAdapter. However, I want to attach an OnNavigationListener to it, and that is where I am having this problem: it has no effect. It only gets triggered one time when I attach it to the actionbar for the first time. Here is my OnNavigationListener implementation:

class RaditazActionBarListener implements ActionBar.OnNavigationListener {
    @Override
    public boolean onNavigationItemSelected(int itemPosition, long itemId) {
        Intent parentActivityIntent = new Intent(ctx, Player.class);
        startActivity(parentActivityIntent);
        return true;
 }

And here is how I am attaching it to my action bar:

getActionBar().setListNavigationCallbacks(mySpinnerAdapter, new RaditazActionBarListener());

Any idea why the listener is not being triggered when I select items in the dropdown?

Thanks, Igor


Solution

  • Since there is no code for mySpinnerAdapter it is hard to guess:

    1. Maybe you are trying to select an already selected item (which will give no callback).
    2. Maybe this item you are trying to select is the only one in the list (guessing from your OnNavigationOtemSelected() code)
    3. A bunch of other possible reasons