0

I have three tabs that each has its own Activity. The tabs are as follows:

Home [HomeActivity]
Search [SearchActivity]
Account [AccountActivity]

I have a Main Activity which handles the main TabHost object and this is its content:

public TabHost tabHost;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tabHost = getTabHost();      

tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("Home").setContent(new Intent(this, HomeActivity.class)));

tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("Search").setContent(new Intent(this, SearchActivity.class).putExtra("callX", true)));
tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator("Account").setContent(new Intent(this, AccountActivity.class)));
tabHost.setCurrentTab(0);
}

Now I have a button in Search tab which I need when it is clicked, no matter what, the Home tab should activate. I guess I should somehow call the setCurrentTab() method on tabHost object but I don't how to access it inside the SearchActivity class?
I probably should use Intent for that which I have no idea how to use.

2hamed
  • 8,719
  • 13
  • 69
  • 112
  • The answer : http://stackoverflow.com/questions/2541802/android-switch-tabs-from-within-an-activity-within-a-tab – user Feb 19 '12 at 14:00

1 Answers1

1

set a method to my main class, which extends TabActivity let's call it "MainActivity"

public TabHost getMyTabHost() { 
return tabHost; 
}

Then add my tab activity class;

MainActivity ta = (MainActivity) this.getParent();
TabHost th = ta.getMyTabHost();
th.setCurrentTab(0);

or follow a better aproach at this

Community
  • 1
  • 1
Akram
  • 7,548
  • 8
  • 45
  • 72