开发者

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 ?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜