I tried this wizard once, and I think I completely discarded the generated code when I applied this exact pattern using ActionBarSherlock, so I suggest starting with a normal "empty" activity from scratch. Here is a short walkthrough. Not all steps are fully described, but you should find enough documentation with keywords to get started.
1) Add ActionBarSherlock to your project (obviously)
2) Create a new action that extends SherlockFragmentActivity and sets the correct abs theme
At this point, you should have empty activity with the action bar.
3) Change the layout and enable the ViewPager, which fills the viewport
4) Write your snippets (or placeholders) and adapter for ViewPager, connect them together
There are many textbooks that explain everything that is needed here, for example. This is a blog post .
That should give you an action with an action bar and custom layout. Now you can draw between your fragments.
5) Add tabs to the action bar and attach a blank tab to them
Example:
actionBar = getSupportActionBar(); sampleTab = actionBar.newTab() .setText(R.string.title) .setTag(TABTAG_SAMPLE) .setTabListener(tabListener); actionBar.addTab(sampleTab);
Make sure you give each of your tabs a separate tag (the string const is fine). This will be used to determine which tab is pressed in a second. Also, make sure that you save the created tab instances in the class variable. You will need them later. Repeat the above snippet for each tab. You can use a regular TabListener, but I recomment using SimpleTabListener, since you only need to override one method later.
You should now have activity with an action bar, scrollable snippets, and (non-functional) tabs.
6) Fill the tab listener and connect it to the viewpager
private SimpleTabListener tabListener = new SimpleTabListener() { @Override public void onTabSelected(Tab tab, FragmentTransaction ft) { final String tag = (String) tab.getTag(); if (TABTAG_SAMPLE.equals(tag)) { viewPager.setCurrentItem(INDEX_SAMPLE); } else if (TABTAG_SECONDTAB.equals(tag)) { viewPager.setCurrentItem(INDEX_SECONDFRAGMENT); } } };
It should be easy. You listen to the tab selection event, check which tab is selected using the saved tag, and call the viewpagers setCurrentItem() method with the fragment index associated with the specific tab.
Now you can select a fragment using the tab, and also swipe the screen. You will notice that scrolling to a specific fragment does not synchronize tabs accordingly, they will not be correctly selected.
7) Attach OnPageChangeListener to ViewPager and select tabs accordingly
Again, you can use SimpleOnPageChangeListener here, and not instead of an interface. A brief example:
private SimpleOnPageChangeListener onPageChangeListener = new SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { switch (position) { case INDEX_SAMPLE: actionBar.selectTab(sampleTab); break; case INDEX_SECONDFRAGMENT: actionBar.selectTab(secondTab); break; } }; };
It should also be self-evident. You observe the action of the swipe, which changes the displayed fragment, checks its index and selects the corresponding tab. You see why you needed to save tab instances from step 5, you need to select the tab.
Now everything should work.