Reputation: 339
I have class CustomTab extends TabActivity:
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.custom_tab);
tabHost = getTabHost();
Intent intentA = new Intent(getBaseContext(), A.class);
Intent intentB = new Intent(getBaseContext(), B.class);
Intent intentC = new Intent(getBaseContext(), C.class);
TabSpec tabA = tabHost
.newTabSpec("a")
.setIndicator("",
getResources().getDrawable(R.drawable.icon_a))
.setContent(intentA);
TabSpec tabB = tabHost
.newTabSpec("b")
.setIndicator(
"",
getResources()
.getDrawable(R.drawable.icon_b))
.setContent(intentB);
TabSpec tabC = tabHost
.newTabSpec("c")
.setIndicator("",
getResources().getDrawable(R.drawable.icon_c))
.setContent(intentC);
tabHost.addTab(tabA);
tabHost.addTab(tabB);
tabHost.addTab(tabC);
tabHost.setCurrentTab(0);
and activity B:
Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.b);
((CustomTab) getParent()).getTabHost().setCurrentTab(3);
I want switch to tab 3(activity C) when run activity B so I tried with "((CustomTab) getParent()).getTabHost().setCurrentTab(3);" it only change tab, but content not change, I created a topic similar but not receive correct answer.
Upvotes: 0
Views: 593
Reputation: 14322
I managed this things calling TabActivity again.
In TabActivity
int tabNumber = getIntent().getExtras().getInt("tabNumber");
tabHost.setCurrentTab(tabNumber);
And calling TabActivity in child Activity like your Activity B like this,
Intent intent = new Intent(BActivity.this,
CustomTab.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("tabNumber",3);
startActivity(intent);
Dont no its correct solution for this or not. but I havn't got any other solution. So, i used this.
Upvotes: 1