Created
January 31, 2012 03:33
-
-
Save nitindhar7/1708585 to your computer and use it in GitHub Desktop.
Fragment - getting fancy - detecting tab changes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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