Android: Start Activity on tab change -


i have following class in java. purpose design tabhost , have activity start when first tab displayed. want have different activity start when tab clicked. have implemented ontabchanged method doesn't seem work. can me?

here class:

public class tabs extends activity implements ontabchangelistener{  @override protected void oncreate(bundle savedinstancestate) {     // todo auto-generated method stub     super.oncreate(savedinstancestate);     setcontentview(r.layout.tabs);     tabhost th = (tabhost) findviewbyid(r.id.tabhost);     th.setup();     tabspec profile = th.newtabspec("tag1");     profile.setcontent(r.id.tab1);     profile.setindicator("", getresources().getdrawable(r.drawable.profile_tab));      tabspec matches = th.newtabspec("tag2");     matches.setcontent(r.id.tab2);     matches.setindicator("", getresources().getdrawable(r.drawable.matches_tab));      tabspec friends = th.newtabspec("tag3");     friends.setcontent(r.id.tab3);     friends.setindicator("", getresources().getdrawable(r.drawable.friends_tab));      th.addtab(profile);     th.addtab(matches);     th.addtab(friends); }  @override public void ontabchanged(string arg0) {     // todo auto-generated method stub }  } 

this tabs.xml layout file:

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" >  <tabhost     android:id="@+id/tabhost"     android:layout_width="match_parent"     android:layout_height="match_parent" >      <linearlayout         android:layout_width="match_parent"         android:layout_height="match_parent"         android:orientation="vertical" >          <tabwidget             android:id="@android:id/tabs"             android:layout_width="match_parent"             android:layout_height="wrap_content" >         </tabwidget>          <framelayout             android:id="@android:id/tabcontent"             android:layout_width="match_parent"             android:layout_height="match_parent" >              <linearlayout                 android:id="@+id/tab1"                 android:layout_width="match_parent"                 android:layout_height="match_parent" >                 <include layout="@layout/activity_main"/>             </linearlayout>              <linearlayout                 android:id="@+id/tab2"                 android:layout_width="match_parent"                 android:layout_height="match_parent" >                 <include layout="@layout/matches_page"/>             </linearlayout>              <linearlayout                 android:id="@+id/tab3"                 android:layout_width="match_parent"                 android:layout_height="match_parent" >             </linearlayout>         </framelayout>     </linearlayout> </tabhost>  </linearlayout> 

you miss th.setontabchangelistener(this);

you have inform tabhost implementation of ontabchangelistener interface has call


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -