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 9134033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:35:25+00:00 2026-06-17T08:35:25+00:00

I have a menu item with a spinner layout and its appearing properly in

  • 0

I have a menu item with a spinner layout and its appearing properly in my action bar’s menu. However, when I click on the spinner, nothing is happening. I have log messages in the onOptionsItemSelected and I’m not seeing any message in logcat. Here are snippets of my code:

Menu layout

<menu xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:id="@+id/menu_item_1"
          android:orderInCategory="100"
          android:showAsAction="always"
          android:actionLayout="@layout/spinner_layout"  />
</menu>

Spinner Layout

<?xml version="1.0" encoding="utf-8"?>
<Spinner xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:background="@drawable/spinner_drawable">
</Spinner>

MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_main, menu);
    spinner = (Spinner) menu.findItem(R.id.menu_item_1).getActionView();

    MySpinnerAdapter spinnerAdapter = new MySpinnerAdapter(this);
    spinner.setAdapter(spinnerAdapter);
    spinner.setOnItemSelectedListener(spinnerAdapter);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    log.error("ON OPTIONS ITEM SELECTED FOR ITEM: " + item.getItemId());

    switch (item.getItemId()) 
    {
        case R.id.menu_item_1:
            log.error("ON OPTIONS ITEM SELECTED - SPINNER MENU ITEM SELECTED");
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}

MySpinnerAdapter.java

@Singleton
public class MySpinnerAdapter extends ArrayAdapter implements SpinnerAdapter, OnItemSelectedListener{

@Inject
public TopbarErrorSpinnerAdapter(Context context) {
    super(context, R.layout.my_spinner_item);
    this.values = Collections.synchronizedList(new ArrayList<MySpinnerRowEntry>());
    this.context = context;
    this.setDropDownViewResource(R.layout.my_spinner_item);
}

@Override
public int getCount() {
    return values.size();
}

@Override
public MySpinnerRowEntry getItem(int position) {
    return values.get(position);
}

@Override
public long getItemId(int position) {
    return position;
}

@Override
public View getView(int position, View view, ViewGroup viewGroup) {

    View row = View.inflate(context, R.layout.my_spinner_item, null);
    ImageView image = (ImageView) row.findViewById(R.id.my_spinner_item_icon);

    return image;
}

@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {

    final int rowPosition = position;

    View row = View.inflate(context, R.layout.my_spinner_item, null);

    TextView title = (TextView) row.findViewById(R.id.my_spinner_item_title);
    title.setText(values.get(position).getTitle());

    TextView message = (TextView) row.findViewById(R.id.my_spinner_item_message);
    message.setText(values.get(position).getMessage());

    row.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mySpinnerAdapterlistener.mySpinnerItemSelected(values.get(rowPosition).getType());
        }
    });

    return row;
}

@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
    MainActivity activity = (MainActivity) context;
    (activity).onOptionsItemSelected((MenuItem) activity.findViewById(R.id.menu_item_1));
}

@Override
public void onNothingSelected(AdapterView<?> parent) {

}

}

I’m also unsure how to trigger the Spinner if the menu item selected is the spinner. I had this same spinner working in a previous activity that didn’t include an ActionBar. Due to changes in my application after upgrading to SDK 14, I know have to add the spinner to the Menu of the ActionBar.

Thank you all for your help in advance.

  • 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-17T08:35:26+00:00Added an answer on June 17, 2026 at 8:35 am

    I’ve managed to resolve my problem using the ActionProvider. I had to define an ActionProvider for the menu item in the xml code, and implement the provider. in the OnCreateActionView, this is where I instantiate the spinner adapter and assigned it to the spinner.
    One thing to point out is that the OnCreateActionView() method has been deprecated and another implementation OnCreateActionView(MenuItem menuItem) is made available. However, if you want your code to work on something like API 14 and API 16, you will have to implement both methods (identically).
    Hope this helps others…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a refresh menu item in the action bar and my main layout
I have a menu item as part of my action bar menu, and I
i have a menu item, and i'm trying to assign its OnClick event handler:
I have a menu item Home in my main menu AND in my top
I have a menu item to which I add another item. Now I want
I have a menu item which has children menu items. When one of the
I have a Menu page. If a user selects an Menu Item it opens
I've defined a custom content type - news. I also have a menu item
I have asp.net Menu Item <asp:MenuItem NavigateUrl= Text=Download Value=Download/> . When this item gets
I have a main menu window. On clicking any menu item it opens a

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.