What is usage of parameter tag used in TabHost.newTabSpec
May I know, for the following code.
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("artists").setIndicator("The Artists",
res.getDrawable(R.drawable.ic_tab_artists))
.setContent(intent);
What is the purpose of having "artists" tag as the parameter of newTagSpec
? Should I use an internationalize string like
spec = tabHost.newTabSpec(getString(R.string.artists)).setIndicator(getString(R.string.the_artists),
res.getDrawable(R.drawable.ic_tab_ar开发者_如何学Pythontists))
.setContent(intent);
The tag parameter is the ID for the tab used by TabHost. The tag might be useful when overriding TabHost methods, e.g.
TextView t = (TextView) findViewById(R.id.nav_bar);
...
tabHost.setOnTabChangedListener(new OnTabChangeListener() {
@Override
public void onTabChanged(String tabID){
t.setText(tabID);
}
});
In this example t is an TextView representing an "navigation bar" and tabID is the tag of the tab that the user switched to. The purpose of this simple overriden method is to change the text inside the navigation bar to the name/tag of the tab.
I did that for all my tabs but you do it like so:
spec = tabHost.newTabSpec("groups").setIndicator(getString(R.string.tab_groups), res.getDrawable(R.drawable.ic_tab_groups)).setContent(intent);
The "groups" is how it figures out R.drawable.ic_tab_NameInNewTabSpec.
精彩评论