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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:07:57+00:00 2026-05-28T14:07:57+00:00

I have an Android app that uses ActionBar Sherlock. I create a menu that

  • 0

I have an Android app that uses ActionBar Sherlock. I create a menu that has an ImageButton whose state is defined in a drawable resource file. (All of them pasted below).

Although I am able to toggle the selected / not selected states of the ImageButton the click listener does not seem to fire.

When the activity is created I inflate the menu, I get the ImageButton and I register the event listener. I debugged and it all seems ok (I am registering the event on the correct ImageButton).

What do you think could cause the ImageButton to not get the onClick callback?

Cheers….

here’s some code:

menu:

<menu xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:id="@+id/menu_save"
          android:showAsAction="always|withText"           
          android:actionLayout="@layout/menu_my_activity"
          />     
</menu>

the menu_my_activity:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/imageButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/button_with_states"
        android:clickable="true" />    
</LinearLayout> 

and the registering of the listener:

public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = (MenuInflater) this.getMenuInflater();
    inflater.inflate(R.menu.menu_watchlist, menu);
    menu.getItem(0).getActionView().findViewById(R.id.imageButton).setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
      Log.d("Test", "Hello");   
    }
        });

    return super.onCreateOptionsMenu(menu);
}
  • 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-05-28T14:07:57+00:00Added an answer on May 28, 2026 at 2:07 pm

    Here’s my suggested fix. There really isn’t any need for a separate actionLayout since the result you want is pretty simple as it is. Note that we don’t need to create an “ImageView” for the ActionBar… the android:icon attribute sets that up for us. Use android:title to set the icon’s text.

    menu_watchlist.xml:

    <menu xmlns:android="http://schemas.android.com/apk/res/android" >
        <item android:id="@+id/image_button"
              android:showAsAction="always|withText"           
              android:title="title"
              android:icon="@drawable/button_with_states" />     
    </menu>
    

    setup options menu:

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_watchlist, menu);
        return super.onCreateOptionsMenu(menu);
    }
    
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.image_button:
                Log.d("Test", "Hello");
                break; 
        }
        return super.onOptionsItemSelected(item);
    }
    

    Hope this works for you!

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

Sidebar

Related Questions

I'm developing for Android and I have an app (called Forget-Me-Not) that uses a
I have an Android app that uses the AlarmService. According to the docs, I
I have a current Android app that uses i18n via resources. res/values-es/strings.xml and so
I have an Android App that uses a TabHost layout. Every tab calls the
recently I been trying to create an android app that uses JSON Objects to
I have an app that uses fragments.I'm using backward compability package with Android 2.2.
I have got my android app that uses HttpClient to reach my servlet deployed
I have an Android app that uses the NotificationManager to inform the user of
I'm helping a friend create an android app that will have screens with lists
I have an app that uses the Android licensing. I'm using the ServerManagedPolicy which

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.