Jignesh Ansodariya
Jignesh Ansodariya

Reputation: 12695

onTabChanged method is not inwalking,

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

Answers (1)

waqaslam
waqaslam

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

Related Questions