Skip to content

Instantly share code, notes, and snippets.

@nitindhar7
Created January 31, 2012 03:33
Show Gist options
  • Save nitindhar7/1708585 to your computer and use it in GitHub Desktop.
Save nitindhar7/1708585 to your computer and use it in GitHub Desktop.
Fragment - getting fancy - detecting tab changes
// Listener to detect when a tab has changed. I added this just to show
// how you can change UI to emphasize the selected tab
tabHost.setOnTabChangedListener(new OnTabChangeListener() {
@Override
public void onTabChanged(String tag) {
// reset some styles
clearTabStyles();
View tabView = null;
// Use the "tag" for the tab spec to determine which tab is selected
if (tag.equals("home")) {
tabView = getTabWidget().getChildAt(0);
}
else if (tag.equals("users")) {
tabView = getTabWidget().getChildAt(1);
}
tabView.findViewById(R.id.tabSelectedDivider).setVisibility(View.VISIBLE);
}
});
private void clearTabStyles() {
for (int i = 0; i < getTabWidget().getChildCount(); i++) {
tab = getTabWidget().getChildAt(i);
tab.findViewById(R.id.tabSelectedDivider).setVisibility(View.GONE);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment