user533844
user533844

Reputation: 2063

ActionBar Tab Selection

 public class TaskDetailTabHome extends Activity implements ActionBar.TabListener{

 @Override
    public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.tablayout);

         ActionBar bar = getActionBar();
         bar.addTab(bar.newTab().setText("TASK").setTabListener(this));        
         bar.addTab(bar.newTab().setText("COMMENT").setTabListener(this));        
         bar.addTab(bar.newTab().setText("FLIGHT").setTabListener(this));        

         bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_USE_LOGO);        
         bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);        
         bar.setDisplayShowHomeEnabled(true);        

         bar.setDisplayShowTitleEnabled(false);

 }
@Override
public void onTabReselected(Tab arg0, FragmentTransaction arg1) {

}
@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
     // Here what I would like to do is ...
     // if (tabselect is TASK)
     // Go to Task.class
     // if (tabselected is COMMENT)
     // Go to Comment.class
}
@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {

}

}

What do I do in onTabSelected method ? Do I need that Fragment ?

Upvotes: 0

Views: 1523

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006724

What do I do in onTabSelected method ?

Update your UI to reflect the selected tab. This could involve:

  • Using the supplied FragmentTransaction to replace a fragment
  • Replacing the child View of a FrameLayout
  • Setting the active child of a ViewFlipper
  • Etc.

Do I need that Fragment ?

You do not appear to have a fragment.

 // Here what I would like to do is ...
 // if (tabselect is TASK)
 // Go to Task.class
 // if (tabselected is COMMENT)
 // Go to Comment.class

You do not use tabs to "go to" something. You use buttons, menus, list item clicks, etc. to "go to" another activity.

You use tabs to show something. That "something" could be implemented by other classes, if they are Fragments or are ViewGroups.

Upvotes: 1

Related Questions