Josh Lillie
Josh Lillie

Reputation: 106

Update tabs from a tab's activity in a Android TabHost

I have a TabActivity and am going to have 3 or 4 tabs.

In TabA, I would like to have an ExpandableListView, which will list products. I would like TabC to act as a sort of "shopping cart", probably with a ListView of itself.

Is there a way to interact with the TabHost from the Activity? I would like to be able to click a button inside of TabA and have it update and switch to TabC. Is this possible? Can I get the Tab's activities call its parents methods?

Upvotes: 9

Views: 21176

Answers (4)

Randy V
Randy V

Reputation: 31

Try to use this code to change activity within a tab:

TabActivity parent = (TabActivity) getParent();
TabHost tabhost = parent.getTabHost();
tabhost.setCurrentTab(0);

Upvotes: 3

Jack Cheung
Jack Cheung

Reputation: 263

  1. In your Activity, use getParent() to get the TabActivity parent
  2. In your TabActivity class, use getLocalActivityManager().getActivity(tabId) to get the Activity object
  3. call the Activity object's method

Upvotes: 1

m6tt
m6tt

Reputation: 4223

You can call getTabHost from a TabActivity, see public TabHost getTabHost().

See Tabhost for setCurrentTab, public void setCurrentTab(int index).

Upvotes: 1

CommonsWare
CommonsWare

Reputation: 1006674

If you implement your tabs as views, rather than individual activities, this would be far simpler, run faster, take up less memory, and be a better solution IMHO.

That being said, in the Tab A Activity, call getParent() to get at the TabActivity. Then, you can use the methods pointed out by disretrospect.

Upvotes: 16

Related Questions