How to change item in a spinner in ActionBar programmatically

android, spinner

Solution

Not sure but probably:

getSupportActionBar().setSelectedNavigationItem(itemPosition);

Docs

Problem

I have a spinner in my ActionBarSherlock with 5 elements in it. By clicking one of the two buttons at the bottom of the screen (see picture) I want to change the `item id` of the `spinner`. This is the relevant code: ``` @Override public void onCreate(Bundle savedInstanceState) { /* ... some code ...*/ Context context = getSupportActionBar().getThemedContext(); ArrayAdapter<CharSequence> list = ArrayAdapter.createFromResource(context, R.array.arr_contents, R.layout.sherlock_spinner_item); list.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item); getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); getSupportActionBar().setListNavigationCallbacks(list, this); getSupportActionBar().setDisplayShowHomeEnabled(false); getSupportActionBar().setTitle(title); /*... some other code ...*/ } @Override public boolean onNavigationItemSelected(int itemPosition, long itemId) { switch(itemPosition) { case 0: // Do stuff break; case 1: // Do stuff break; case 2: // Do stuff break; case 3: // Do stuff break; case 4: // Do stuff break; default: // Do stuff break; } return true; } ``` I've tried calling `onNavigationItemSelected(3, R.array.arr_contents);` for example to move to the third element of the spinner but it doesn't work. How can I do it?

Original source