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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:38:52+00:00 2026-05-15T12:38:52+00:00

Can someone please tell me how to change tab by clicking on element INSIDE

  • 0

Can someone please tell me how to change tab by clicking on element INSIDE the tab? I already tried it with global data. The code looks like this:

public class Tabs extends TabActivity {

int tabNumber = 0;
private TabHost tabHost;
int returnedTabNumber = 0;

/** 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 = 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, Tribocracy.class);

    // Initialize a TabSpec for each tab and add it to the TabHost
    spec = tabHost.newTabSpec("map").setIndicator("Map",
                      res.getDrawable(R.drawable.ic_tab_artists))
                  .setContent(intent);
    tabHost.addTab(spec);

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

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

    tabHost.setCurrentTab(tabNumber);


}

protected void onResume() {
    super.onResume();


            GlobalData globalData = ((GlobalData)getApplicationContext());
            returnedTabNumber = globalData.getTabNumber();
            tabHost.setCurrentTab(returnedTabNumber);   


}

}

The global adapter looks like this:

public class GlobalData extends Application {
//----------------------------------------------------
      private int Point1;   //define the vars here
      private int Point2;   //define the vars here
      private int Point3;   //define the vars here
      private int Point4;   //define the vars here
      private int Point5;   //define the vars here
      private int Point6;   //define the vars here
      private int tabNumber;

      public int getTabNumber() //getter of the value
      {     
        return tabNumber;
      }

      public int setTabNumber(int number)     //setter of the value
      {
        tabNumber = number;
        return tabNumber;
      }

}

Now when I’m trying to change tab in my ListActivity tab by clicking on one of the items it doesn’t do anything and stays on the ListActivity tab. Perhaps I shouldn’t use onResume() here. Basically I want to go to first tab when I click on one of the items in the list. Please 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-15T12:38:53+00:00Added an answer on May 15, 2026 at 12:38 pm

    One way to do this is to use Intents. And there are many ways to use Intents for this. This works especially well for some cases, for example where the activity is displaying some content from a content provider. I’ll describe one possible method below:

    1. For the Activity that hosts the tabs, give it an intent filter if it doesn’t already have one. For example, if it’s an ‘item detail’-style Activity, maybe its intent filter can match for ACTION_VIEW on a certain content type like vnd.android.cursor.item/vnd.somecontent.
    2. Have the Activity take an extra such as focus_tab, and in the Activity’s onCreate, after setting up the tabs, set the active tab to the one specified by this focus_tab extra.
    3. Override onNewIntent, and in that method, look for that same focus_tab extra and set the active to the one specified by that extra.
    4. Now, in your button code (i.e. a button inside one of your tab content activities), create an Intent that will start your host Activity, and give it a focus_tab extra corresponding to the tab you want to switch to. Add the FLAG_ACTIVITY_SINGLE_TOP Intent flag so you don’t create a new instance of the host Activity. And then, call startActivity on that Intent you just created.

    Note: I haven’t tried this myself, but it should work in theory.

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

Sidebar

Related Questions

Can someone please tell me how I can implement the following line of pseudo-code.
Can someone please tell me whats wrong with this code. I'm not getting complete
Could someone please tell me how can I change the default css of a
Can someone please tell me what's wrong with this code? Basically what I am
Can someone please tell me what this means: 07-04 09:54:38.048: I/DetailActivity(15496): Title that is
Can someone please tell me why I'm getting the error object reference is required
Can someone please tell me how to disable the keyboard in a Text View?
Can someone please tell me what's wrong with this sp. The logic seems to
Can someone please tell me why this doesn't work? I'm trying to show and
Can someone please tell me ehy in IE 6 div is not in center.

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.