1

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

IgorGanapolsky
  • 26,189
  • 23
  • 116
  • 147

1 Answers1

4

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
Alex Semeniuk
  • 1,865
  • 19
  • 28
  • Yes, this is the only item in the list. But shouldn't the selection work anyway? – IgorGanapolsky Mar 11 '13 at 15:03
  • 2
    No, it should not. Listener is called only when current selection *is changed*. To override this behavious for common Spinner the approach [suggested here](http://stackoverflow.com/questions/10854329/spinner-onitemselected-not-called-when-selected-item-remains-the-same) can be used. The source code of *ActionBarSherlock* can be modified if you are using it. If not - the only option left is using custom layout for action bar (which is not very hard to achieve). – Alex Semeniuk Mar 12 '13 at 14:29