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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:51:36+00:00 2026-05-23T12:51:36+00:00

Newbee to Android development. I am developing a application, which have three different tabs.

  • 0

Newbee to Android development.
I am developing a application, which have three different tabs. I want to have common menu options, like About and Refresh, on all tabs and in each individual need the specific menu accordingly.

MyAPP Main():

public class MyApp extends TabActivity {
    /** Called when the activity is first created. */

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Resources res = getResources(); // Resource object to get Drawables
        TabHost tabHost = getTabHost();  // The activity TabHost
        TabHost.TabSpec spec;  // Resusable TabSpec for each tab
        Intent intent;  // Reusable Intent for each tab

        // Create an Intent to launch an Activity for the tab (to be reused)
        intent = new Intent().setClass(this, Bundles.class);
        // Initialize a TabSpec for each tab and add it to the TabHost
        spec = tabHost.newTabSpec("bundles").setIndicator("Bundles",
                          res.getDrawable(R.drawable.ic_tab_bundle_grey))
                      .setContent(intent);
        tabHost.addTab(spec);

        // Do the same for the other tabs
        intent = new Intent().setClass(this, Policies.class);
        spec = tabHost.newTabSpec("policies").setIndicator("Policies",
                          res.getDrawable(R.drawable.ic_tab_policy_grey))
                      .setContent(intent);
        tabHost.addTab(spec);

        intent = new Intent().setClass(this, Inventory.class);
        spec = tabHost.newTabSpec("Inventory").setIndicator("Inventory",
                          res.getDrawable(R.drawable.ic_tab_settings_grey))
                      .setContent(intent);
        tabHost.addTab(spec);

        tabHost.setCurrentTab(2);
    }
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.layout.menu, menu);
    return true;
}

public void onClick(View v) {
    switch(v.getId()) {
    case R.id.about:
        Intent i = new Intent(this, About.class);
        startActivity(i);
        break;            
    case R.id.refresh:
        Intent j = new Intent(this, RefreshAgent.class);
        startActivity(j);
        break;
    // more buttons to go here later
    }
}

In other Inventory tab:

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

    public void onClick(View v) {
        switch(v.getId()) {
        case R.id.register:
            Intent i = new Intent(this, About.class);
            startActivity(i);
            break;            
        case R.id.reregister:
            Intent j = new Intent(this, Reregister.class);
            startActivity(j);
            break;
        case R.id.accountsettings:
             Toast.makeText(this, "Account Settings", Toast.LENGTH_LONG).show();
            break;

        }
    }
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case R.id.register:
            Toast.makeText(this, "Registration Not implemented!", Toast.LENGTH_LONG).show();
            return true;
        case R.id.reregister:
            Toast.makeText(this, "Re Registration Not implemented!", Toast.LENGTH_LONG).show();
            //TODO : Use refresh agent class
            //startActivity(new Intent(this, RefreshAgent.class));
            return true;
        case R.id.accountsettings:
            //Intent j = new Intent(this, RefreshAgent.class);
            //startActivity(j);
            Toast.makeText(this, "Account Settings", Toast.LENGTH_LONG).show();
            break;
        }
        return false;

Above implementation displays About and Refresh on other two tabs, but on Inventory tab it displays only two which are defined in Inventory tab.

Thanks in advance for the help.

  • 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-23T12:51:36+00:00Added an answer on May 23, 2026 at 12:51 pm

    I didn’t know if your two code sample are in the same class (i never used tabactivity) but i will anwser in both case.

    • If inventory tab are in another class than MainApp :

    In the first code sample, you do

    inflater.inflate(R.layout.menu, menu);
    

    It is this line who show the about and refresh menu.
    In your inventory tab, you inflate R.layout.settings_menu , which do not contain about and refresh, that is why you don’t have common menu in all your tab.

    You need to inflate, in all your tab R.layout.menu (which i advise you to rename common_menu).

    By example, on inventory tab, you just need to do that :

    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.layout.menu, menu);
    inflater.inflate(R.layout.settings_menu, menu);
    return true;
    

    Menu are inflated in that order, so you will see common menu on bottom, and the specific menu on the top.

    If you are motivated, you can probably do a “base activity” who would inflate on onCreateOptionMenu the common menu, and in your specific activity (who would extend your base activity), you could call super.onCreateOptionMenu(), and inflate what you need after.

    • If There are in the same class :

    You need to inflate another menu in function of the current tab showed. There is one problem tough, the onCreateOptionMenu is only called once by activity, so if you change the tab and press menu, it will just show the precedent menu.

    Fortunatelly, there is another method that you can use too. It’s onPrepareOptionMenu(). This method is called every time you show the menu in your application. So, you just need to inflate your specific menu in here.
    You can read this link : http://developer.android.com/guide/topics/ui/menus.html

    But basically, you just have to do that :

    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
        if(Tab == Inventory) {
            inflater.inflate(R.layout.settings_menu, menu);
        }
    return true;
    }
    

    And keep your first onCreateOptionMenu, who will inflate the common menu each time.

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

Sidebar

Related Questions

I am newbie in android .i want to develop an application which has the
I'm newbie in Android application development. I just downloaded all SDks and Eclispe. Then
I want to create an Android application that has a MapView at the top
I am a newbie to Android app development. For 1 of my project, I
This might sound stupid, but I'm seriously a newbie at Android programming. I have
Newbie question. I have a NSMutableArray that holds multiple objects (objects that stores Bezier
Newbie here...can I write one program which incorporates .NET LINQ and also various Java
Java Newbie here. I have a JFrame that I added to my netbeans project,
.NET newbie here... I'd like to make a button in a Windows form that
I'm a newbie to pgsql. I have few questionss on it: 1) I know

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.