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

  • Home
  • SEARCH
  • 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 8218063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:39:38+00:00 2026-06-07T12:39:38+00:00

I am using ActionBarSherlock to implement an UI using this powerful AB as a

  • 0

I am using ActionBarSherlock to implement an UI using this powerful AB as a Menu. This is the menu layout:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
        android:id="@+id/capturador"
        android:icon="@drawable/ic_action_capturador"
        android:showAsAction="always"
        android:title="@string/capturador"/>

    <item
        android:id="@+id/preferencias"
        android:icon="@drawable/ic_action_prefs"
        android:showAsAction="always"
        android:title="@string/preferencias"/>   

</menu>

As you can see it has two items (capturador and preferencias)

So, what I wanna do -if it’s possible- is to re-use code. It’s not a big deal because I just have two more activities apart from Main activity but what if I had five? Should I overwrite in each activity the onOptionsItemSelected(MenuItem item) and onCreateOptionsMenu(Menu menu) methods?

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getSupportMenuInflater();
    inflater.inflate(R.menu.main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.capturador) {
        startActivity(new Intent(this, Capturador.class));
    } else if (item.getItemId() == R.id.preferencias) {
        startActivity(new Intent(this, Ajustes.class));
    }
    return true;
}

Thanks in advance for your help and sorry if this question was already answered but I don’t really know which words I must use to try to find it (besides, English is not my mother tongue)

  • 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-07T12:39:39+00:00Added an answer on June 7, 2026 at 12:39 pm

    Just make an BaseActivity in which you implement this code, and then let all your Activities that you want to have this 2 options menu, extend your BaseActivity.

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

Sidebar

Related Questions

I am using ActionBarSherlock to implement action bar for Android 2.1 platform. But in
I am using ActionBarSherlock to implement action bar on my Android 2.1 API 7
I'm using ActionBarSherlock in my Android project, and it's awesome. One small issue: My
I'm using ActionBarSherlock in an Android project that I developed using Eclipse. I'd like
My own project is using Android 2.1 API 7 . To implement action bar,
I'm using ActionBarSherlock to implement an ActionBar with tabs in my application. When I
If I'm using ActionBarSherlock, and My activity looks like this in Ice Cream Sandwich:
I am using ActionBarSherlock and have implemented ShareActionProvider . When a user selects an
I'm using ActionBarSherlock and have a little problem. In the Fragment Tabs example, there
I'm developping an application using ActionBarSherlock component. My goal is to target all devices

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.