How do i add a spinner to the title bar of an activity?
Asked Answered
G

1

8

I tried to set a custom title bar includes spinner object but everytime it gave me that exception called "You cannot combine custom titles with other title features". I searched to find a solution site by site and also i did everything correctly as described on the net but the exception never disappeared. There is a very silly question left on my mind that it can be related to android 3.0? I am developing with version 3.0 (honeycomb). I don't know what should i do.

Thank you adamp, i made it with your guidance. here is a simple action bar with spinner example. May help to someone who is facing the similar issue.

    super.onCreate(savedInstanceState);
    setContentView(R.layout.screens);
    ActionBar bar = getActionBar();
    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
    bar.setListNavigationCallbacks(new SpinnerAdapter(this, android.R.layout.simple_dropdown_item_1line, EczaneMgr.getInstance(this).getEczaneListAsSpinner()),
            new OnNavigationListener() {
          @Override
          public boolean onNavigationItemSelected(int position, long itemId) {
            Log.e("item position",String.valueOf(position));
            return true;
            //do whatever want to do...
          }
        }
    );
Gallegos answered 27/8, 2011 at 16:28 Comment(0)
K
7

The Action Bar used on Android 3.0+ is considered a title feature, and your Activity will get one by default if you are using one of the Holo themes. (Theme.Holo, Theme.Holo.Light, etc.) Theme.Holo is the default for apps with targetSdkVersion="11" or above. The older "custom title bar" feature cannot be combined with the action bar, but you can use the action bar to do this instead.

Use the action bar's list navigation mode, set using ActionBar#setNavigationMode and ActionBar#setListNavigationCallbacks to specify an adapter that will supply spinner views.

Krystenkrystin answered 27/8, 2011 at 18:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.