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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:18:35+00:00 2026-05-21T07:18:35+00:00

I need to have a TabHost consisting of two tabs where each tab represented

  • 0

I need to have a TabHost consisting of two tabs where each tab represented by a separate Activity. Each Activity has its own data fields and methods to operate on them. I want each tab to have its own menu and for this menu I need onOptionsItemSelected() method to be a part of the class to make it able to invoke methods of this class.

What the best approach would it be to implement this?

I’ve started with menu definition in the class which represents TabHost, but then faced with a problem I don’t have an access to methods of my Activities. I decided to make methods of Activities static to have access to them but finally I would need to define almost all fields of these Activities as static which doesn’t seem to be a good solution for me.

Update:


It became much easier then I thought. In onOptionsItemSelected() you can get the current Activity of your opened tab.

SecondActivity sa = (SecondActivity)this.getCurrentActivity()
sa.myPublicMethod();
  • 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-21T07:18:35+00:00Added an answer on May 21, 2026 at 7:18 am

    This really depends on what sort of functionality you are implementing. You could have each activity implement an interface with the instance methods you need and then have the tabhost contain a reference to the current activity of type interface. If you do this, make sure to update the reference each time you switch to another activity.

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

Sidebar

Related Questions

I have three tabs that each has its own Activity. The tabs are as
I have a tabhost with some tabs, and each tab have implemented the method
I have an application with various tabs (on a tabhost). Each tab is an
I have problem with initializing TabHost. I need to have in View several Tabs
I have a tabhost with 3 tabs. In each of these tabs there is
I need little bit help related to android tabhost. I have 3 tabs and
I am attempting to create a tab based activity with seven tabs. Tabhost won't
Hi i currently have an Activity that hosts a tab view, and each tab
I'm trying to create a tablayout where have two tabs for now. One tab
I have need for a function pointer that takes two arguments and returns 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.