I use fragments for my implementation of Sherlock.
public class ActionBarTabs extends FragmentActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ActionBar bar = getSupportActionBar(); bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); bar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE); bar.addTab(bar.newTab() .setText("Home") .setTabListener(new TabListener<DashBoardFragment>( this, "home", DashBoardFragment.class, null))); bar.addTab(bar.newTab() .setText("Inventory") .setTabListener(new TabListener<InventoryFragment>( this, "inventory", InventoryFragment.class, null))); if (savedInstanceState != null) { bar.setSelectedNavigationItem(savedInstanceState.getInt("tab", 0)); } } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home:
The key change for loading different fragments into tabs is simply to change "YOUR_FRAGMENT_NAME" to the name of your fragment class in these lines:
bar.addTab(bar.newTab() .setText("Home") .setTabListener(new TabListener<YOUR_FRAGMENT_NAME>( this, "home", YOUR_FRAGMENT_NAME.class, null)));
Hope this helps!
source share