How to use TabHost.OnTabChangeListener in android?
give me some example code... :(
thanks
The user can scroll tabs from left to right or right to left. This example demonstrates how to use tab host in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main.
TabHost consists of two children of which one is FrameLayout (which is used to show the contents of the activity) and another one is TabWidget.
In Android, TabHost is a Container for tabbed window view. This object holds two children one is set of tab labels that the user clicks to select a specific tab and other is a FrameLayout object that displays the content of that page.
why it would be my pleasure to help you good sir:
myTabHost.setOnTabChangedListener(new OnTabChangeListener(){ @Override public void onTabChanged(String tabId) { if(TAB_1_TAG.equals(tabId)) { //destroy earth } if(TAB_2_TAG.equals(tabId)) { //destroy mars } }});
Where TAB_1_TAG
is the tag provided to the newTabSpec
method when creating the tab.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With