Code example for ActionBar.Tab

Methods: setTabListener, setText

0
    tab1.setText("Tab1");
    tab1.setTabListener(new TabListener<Tab1Fragment>(this, "tab1", Tab1Fragment.class));
    actionBar.addTab(tab1);
 
    ActionBar.Tab tab2 = actionBar.newTab();
    tab2.setText("Tab2");
    tab2.setTabListener(new TabListener<Tab2Fragment>(this, "tab2", Tab2Fragment.class));
    actionBar.addTab(tab2);
  } 
 
  @Override 
  public void onItemSelected(String id) {
    boolean mTwoPane = findViewById(R.id.item_detail_container) != null;
    if (mTwoPane) {
      Bundle arguments = new Bundle();
      arguments.putString(ItemDetailFragment.ARG_ITEM_ID, id);
      ItemDetailFragment fragment = new ItemDetailFragment();
      fragment.setArguments(arguments);
      getSupportFragmentManager().beginTransaction() 
          .replace(R.id.item_detail_container, fragment)
          .commit();