Reputation: 12695
My Method onTabChanged() is not called when I clicked the tab bar to change the tab
public class ZoobuzzActivity extends TabActivity implements OnTabChangeListener {
/** Called when the activity is first created. */
TabHost tabHost;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.first_tab);
}
public void onTabChanged(String tabId) {
for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {
tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.RED);
}
tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundColor(Color.GREEN);
}
}
please help me I want to change color when tab selection is change.
Upvotes: 0
Views: 373
Reputation: 68187
You need to set OnTabChangeListener to your TabHost as below:
//set tab change listener
tabHost.setOnTabChangedListener(this);
//where 'this' is a reference to your activity ZoobuzzActivity
Upvotes: 2