Reputation: 1349
I've developed a simple tabwidget with the help of a tutorial. It looks like this:
My goal is: When a user clicks is in the "day Tab" and clicks "Today tab" the today tab must pass the control of today activity back to day activity to show the current day day.
eg. If I am in day tab and I click today tab. The function of the TODAY tab is to show the current date in the day tab. This applies to both Month and Week tab. Which means if a user has month tab active and then clicks today tab: the today tab must show the current month in the same activity.
Data flow: month activity -> today activity -> month activity
How can I achieve this task ?
I've tried to put in simple words, if you didn't understand please tell me. I will rephrase the question.
Here is the code I used to setup my Tabs
public class Secondactivity extends TabActivity {
private TabHost mTabHost;
private void setupTabHost() {
mTabHost = getTabHost();
}
setupTabHost();
mTabHost.getTabWidget().setDividerDrawable(se.copernicus.activity.R.drawable.tab_divider);
setupTab(new TextView(this), getString(R.string.month));
setupTab(new TextView(this), getString(R.string.week));
setupTab(new TextView(this), getString(R.string.day));
setupTab(new TextView(this), getString(R.string.today));
mTabHost.setCurrentTabByTag(getString(R.string.month));
private void setupTab(final View view, final String tag)
{
View tabview = createTabView(mTabHost.getContext(), tag);
if (tag.compareTo(getString(R.string.month)) == 0)
{
Intent intent = new Intent(getApplicationContext(), MonthActivity.class);
TabSpec setContent = mTabHost.newTabSpec(getString(R.string.month)).setIndicator(tabview).setContent(new TabHost.TabContentFactory()
{
public View createTabContent(String tag)
{
return view;
}
});
setContent.setContent(intent);
mTabHost.addTab(setContent);
}
if (tag.compareTo(getString(R.string.week)) == 0)
{
Intent intent = new Intent(getApplicationContext(), WeekActivity.class);
TabSpec setContent = mTabHost.newTabSpec(getString(R.string.week)).setIndicator(tabview).setContent(new TabHost.TabContentFactory()
{
public View createTabContent(String tag)
{
return view;
}
});
setContent.setContent(intent);
mTabHost.addTab(setContent);
}
if (tag.compareTo(getString(R.string.day)) == 0)
{
Intent intent = new Intent(getApplicationContext(), DayActivity.class);
TabSpec setContent = mTabHost.newTabSpec(getString(R.string.day)).setIndicator(tabview).setContent(new TabHost.TabContentFactory()
{
public View createTabContent(String tag)
{
return view;
}
});
setContent.setContent(intent);
mTabHost.addTab(setContent);
}
if (tag.compareTo(getString(R.string.today)) == 0)
{
Intent intent = new Intent(getApplicationContext(), DayActivity.class);
TabSpec setContent = mTabHost.newTabSpec(getString(R.string.today)).setIndicator(tabview).setContent(new TabHost.TabContentFactory()
{
public View createTabContent(String tag)
{
return view;
}
});
setContent.setContent(intent);
mTabHost.addTab(setContent);
}
}
private static View createTabView(final Context context, final String text)
{
View view = LayoutInflater.from(context).inflate(R.layout.tabs_bg, null);
TextView tv = (TextView) view.findViewById(R.id.tabsText);
tv.setText(text);
return view;
}
Upvotes: 0
Views: 327
Reputation: 39470
Try overriding onTabChanged()
and passing your intent or setting your flag there. This may help:
@Override
public void onTabChanged(String tabId) {
switch (tabId)) {
case 0:
// Tab 1
break;
case 1:
// Tab 2
break;
case 2:
// Tab 3
break;
case 3:
// Tab 4
break;
}
}
Upvotes: 2
Reputation: 8242
override onTabChange()
, which will tell you about cureent tab no. and next tab no.
if(nextTab == DayTab)
compare currentTab and acordingly pass a flag to day Tab .
i am not sure whenther you can bind detail with intent , if so use application level data sharing like Application
class implementation or singlton object .
Upvotes: 3