Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8323577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:45:23+00:00 2026-06-08T23:45:23+00:00

I have an activity using ActionBarSherlock with ActionBar.NAVIGATION_MODE_LIST . When entering the page I

  • 0

I have an activity using ActionBarSherlock with ActionBar.NAVIGATION_MODE_LIST.

When entering the page I want the spinner in the action bar to expand programmatically after it’s populated with items so the user needs to pick an item. As of now the first item in the adapter is selected automatically.

I can’t figure out a nice way to expand the spinner in the action bar programmatically. Do I need to use a custom view to achieve this behavior?

I’ve looked on the action bar with the HierarchyViewer and the spinner does not have an id set. Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T23:45:24+00:00Added an answer on June 8, 2026 at 11:45 pm

    Here is code how I create custom action bar with actiobBarSherlock

     private void createCustomActionBar() {
    
        List<SiteLink> links = new ArrayList<SiteLink>();
        links.add(...)  
        LinksAdapter linkAdapter = new LinksAdapter(this, R.layout.external_link, links);
    
        View customNav = LayoutInflater.from(this).inflate(R.layout.custom_show_action_bar, null);
        IcsSpinner spinner = (IcsSpinner)customNav.findViewById(R.id.spinner);
        spinner.setAdapter(linkAdapter);
    
    
        ImageView refresh = (ImageView) customNav.findViewById(R.id.refresh);
        refresh.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ...
            }
        });
    
        ImageView settings = (ImageView) customNav.findViewById(R.id.settings);
        settings.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ...
            }
        });
    
        getSupportActionBar().setCustomView(customNav, new ActionBar.LayoutParams(Gravity.RIGHT));
        getSupportActionBar().setDisplayShowCustomEnabled(true);
    
    }
    

    Adapter

    private static class LinksAdapter extends ArrayAdapter<SiteLink> {
    
        private List<SiteLink> strings;
        private Context context;
    
        private LinksAdapter(Context context, int textViewResourceId, List<SiteLink> objects) {
            super(context, textViewResourceId, objects);
            this.strings = objects;
            this.context = context;
        }
    
        @Override
        public int getCount() {
            if (strings == null) return 0;
            return strings.size();
        }
    
        @Override
        public SiteLink getItem(int position) {
            return super.getItem(position);
        }
    
    
        // return views of drop down items
        @Override
        public View getDropDownView(int position, View convertView, ViewGroup parent) {
    
            final SiteLink siteLink = strings.get(position);
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            // at 0 position show only icon
    
            TextView site = (TextView) inflater.inflate(R.layout.external_link, null);
            site.setText(siteLink.getName());
    
            site.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(siteLink.getUrl()));
                    context.startActivity(i);
                }
            });
            return site;
    
    
        }
    
    
        // return header view of drop down
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            return inflater.inflate(R.layout.icon, null);
        }
    }
    

    Layout

    <?xml version="1.0" encoding="utf-8"?>
    
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:layout_width="fill_parent"
                  android:layout_height="fill_parent"
                   android:gravity="right"
            >
    
    
        <com.actionbarsherlock.internal.widget.IcsSpinner
            android:id="@+id/spinner"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:paddingRight="20dp"
            android:layout_gravity="center"
                />
    
         <ImageView  android:layout_width="fill_parent"
                     android:layout_height="fill_parent"
                     android:src="@drawable/ic_navigation_refresh"
                     android:paddingRight="20dp"
                     android:paddingLeft="10dp"
                     android:layout_gravity="center"
                     android:background="@drawable/action_buttons_background"
                     android:id="@+id/refresh"/>
    
    
        <ImageView  android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:src="@drawable/ic_action_settings"
                    android:paddingRight="20dp"
                    android:background="@drawable/action_buttons_background"
                    android:layout_gravity="center"
                    android:id="@+id/settings"/>
    
    </LinearLayout>
    

    to expand spinner call

     (getSupportActionBar().getCustomView().findViewById(R.id.spinner)).performClick();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Activity class, ListActivity class, TabActivity class. I want expand these classes using
I am using actionbarsherlock library to have action-bar in my application, I am also
I have noticed that when using actionBar.setSelectedNavigationItem(x) in the onCreate() method of my Activity,
I have an activity. In this activity I want to start another activity using
I want to make Activity like this using GridView. And this Activity have only
In my main activity, I have an ActionBar with navigation tabs and action items.
I have an Activity A that calls an Activity B using startActivityForResult() . Under
Hi I have an Activity(Activity_1) which calls another Activity(Activity_2) using activity for result. In
I Have a Service and i interact with it from an activity using Binding.
I have an activity that appears as a dialog using the following custom theme:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.