spec = tabHost.newTabSpec("Starters").setIndicator("Starters").setContent(intent);
spec = tabHost.newTabSpec("MAIN_COURSE").setIndicator("Main Course").setContent(intent);
here Starters
and Main Course
are the titles of tabs. The easiest way to send this strings to bounded activities is to send them throught intents which are bounded to corresponding
tabSpecs.
String TAB_TITLE="Starters";
Intent intent = new Intent().setClass(this, BLD_IndividualListOfItems_Starters.class);
Bundle bundle =new Bundle();
bundle.putString("key_title", TAB_TITLE);
intent.putExtras(bundle);
spec = tabHost.newTabSpec("Starters").setIndicator(TAB_TITLE).setContent(intent);
tabHost.addTab(spec);
And here is how you can get this string in BLD_IndividualListOfItems_Starters
activity :
protected void onCreate(Bundle savedInstanceState) {
...
String title=getIntent().getExtras().getString("key_title");
}
But as Raghunandan says, it's better to use fragments instead of depracated TabActivity
.
EDITED:
if you want to send text to corresponding activity dinamically, i mean exactly after tab is changed - you can:
- create and broadcast custom intent with your string. (CUSTOM_INTENT_EXAMPLE)
- in
BLD_IndividualListOfItems_Starters
activity registerBroadcastReciever
which will catch your custom intent and take text from it. (BROADCAST_RECIEVER_FROM_ACTIVITY_EXAMPLE)
You can't directly access tab text from BLD_IndividualListOfItems_Starters
, because TabActivity
and BLD_IndividualListOfItems_Starters
are two different activities.
But you can send data between activities via bundles, static fields, singletons etc. Here is link to docs
http://developer.android.com/guide/faq/framework.html#3