Android actionbar spinner selected item, subtitle and dropdown list

15,337

Solution 1

To have a different view in the action bar spinner than in the spinner list, you can use a BaseAdapter or an ArrayAdapter and override some methods:

  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    // Return a view which appears in the action bar.

    return yourCustomView..;
  }

  @Override
  public View getDropDownView(int position, View convertView, ViewGroup parent) {
    // Return a view which appears in the spinner list.

    // Ignoring convertView to make things simpler, considering
    // we have different types of views. If the list is long, think twice!
    return super.getView(position, null, parent);
  }

Solution 2

it might be a bit too late, but the tutorial with commented codes can be found on the Android developer website: http://developer.android.com/guide/topics/ui/actionbar.html#Dropdown

the basics is that during the activity OnCreate you have to set it to be a list:

      getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);

and then create a spinner adapter and a couple of callbacks just like you would do with a normal spinner.

hope it helps

Share:
15,337
VladacusB
Author by

VladacusB

Updated on August 12, 2022

Comments

  • VladacusB
    VladacusB over 1 year

    How can I make spinner in action bar to have different item as selected (shown in the action bar top) then the one in the drop down list? Example is google mail with spinner in action bar:

    action_bar_pattern_spinner

    • How did they achieve this functionality?
    • Could I change selected item in action bar without affecting the same item in drop down list?
    • How they changed selected item in action bar to have two rows and different fonts but did not affect item in dropdown list?
    • Is this possible to achieve this with default implementation of action bar spinner in ICS and action bar sherlock or should we try with custom view?

    Any source code, tutorial or document would be really helpful. I already have bind spinner with adapter in action bar and I have list in dropdown menu, but I can not modify in any way item without affecting item in dropdown list (because they are the same thing).

  • VladacusB
    VladacusB over 11 years
    Yes this is the proper solution.
  • Jay Wick
    Jay Wick almost 11 years
    yep, that's how they did it: source