ActionBarSherlock Side Menu Navigation with Nested ViewPager Fragment Tabs Tutorial

  • I’ll check on it. Thanks for your feedback.

  • Umar

    coool !!
    haven’t checked if it works but looking forward to implement the layout on my app 🙂

  • MIKI

    Thaks for that, it realy helps me 😀
    But what can I do when I want TextView or AutoCompeteTextView instead the tile (I mean Title Fragment 1 and Title Fragment 2 in ActionBar) nex to button in top-left

  • Balazs Ruda

    I had the same problem on 2.3.
    I deleted the following line from the drawer_list_item.xml;
    After this, it works fine.

  • Martin JM

    is this App also compatible with android 2.3?

  • Alexander

    Thank you thank you thank you! Worked perfectly. I wanted to put menu items in xml but had trouble parsing out the icon drawables from xml. The following tutorial helped (hint: int[] becomes TypedArray);jsessionid=FBBDB8B566AF5762933354F7F6989661?recipeId=1418

    • Hi there, I’m glad this tutorial helped you. 🙂

  • Alexmuller1416

    how to use intent in the project

  • Tom

    This is makes the app look a lot more professional, thanks for teaching 🙂

  • JoJo

    Please show me how to add action for fragment 1. Thanks

  • anushya subbiah

    hey thanks for the tutorial.. it was great.. i ran it in my emulator. There was no problem.But when i exported there was a problem. eclipse closed abruptly whenever i finished the export procedure. Any solution for this.

  • Fred

    Thank you very very much for the tutorial. its amazing. this might be a stupid question. but can i add more fragments to the drawer menu. and give seperate tabs for the new fragments. if its possible will you please help me. Thanks anyways.

    • Ricardo Bird

      Hi Fred were you able to add more fragments? Please help me! 🙂

  • Artem


    Thanks for the tutorial! But here is one question – why we should use child FragmentManager via getChildFragmentManager() instead of accessing FragmentManger directly? Thanks in advance!

  • Albert John Mwanjesa


    First, thank you for your tutorials, they are very helpful.

    With this tutorial I have one problem. It seems that my ActionbarSherlockProject is missing the ActionbarDrawerToggle widget and also the DrawerLayout widget as well. How do I solve this problem?

    Thank you in advance!

  • Andrew

    I try to load strings from resource like this:
    Original: private String titles[] = new String[] { “Tab1”, “Tab2” };

    Resources titles_array = context.getResources();
    String[] titles = titles_array.getStringArray(R.array.title);

    Unfortunetly app crash always. What else can I do to load titles from resource?

    • NikoWeb

      Hi, I also had the same problem, did you solved? please help me.

      try to do the same but with the slide titles and app crashes

  • Çağrı Çakır

    Great, simple and clear explanation. Thanks.

  • chandu

    very good………….. and thank u for u r Tutorial..

  • Nguyễn Hoàng Anh

    how can I use viewpager tabswipe in actionbar not TabStrip

  • Tony Kim

    Im using webview inside the fragment… i need to load the back page. when back pressed… While im doing so, the application exits. Help me….

  • ProSpartan

    Awesome stuff! Been looking for something like this for ages.

    Question: How can i build my programs without having the Sherlock action bar program in my workspace? I can get the .jar file which is basically all that is needed for most of the programming except for the res files. Is there a way to have those without including them in my program?

  • NikoWeb

    Thank you very much for the article, took 4 days looking for something.

    Please help me to add more tabs.

    I try to do it but the app crashes upon opening when I add the name of the layer in this line of activity.

    Thank you very much.

    • NikoWeb

      After 3 days a silly mistake, I answer myself.

      There was forgetting generating a third menu icon.

      need to add the icon to the fragment 3 to the stretch hdpi folder

      and generate it in the activity.

  • Siju

    I have been trying to implement menu options in child fragment of view pager . But the onCreateOptionsMenu never gets called. Can you pleas help?

  • waseem ahmad

    My Second Tab Is not Responding …I worked As U did In Tutorial …1st tab Is Working ..When I i sweep For Second Not displaying Blank …….

    can u tell whats wrong

  • waseem ahmad

    second Tab Is not Performing ….i mean Content Of Second Tab Is Not Running Please Help

  • waseem ahmad

    can u tell ME How to Update Tabs mean refresh……please rply soon

    • Hi Waseem, I apologize for replying so late. I’ve been busy updating this site. Please ask your questions in stackoverflow. Thank you.

  • Leto


    Thanks for this tutorial. I search for long time to use the NavigationDrawer and the Viewpager and the solution it’s the ActionbarSherlock.

    I have a problem in Fragment2 class. The methode onCreateView doesn’t recognize the call at getChildFragmentManager().
    ActionBarSherlock is in my library and I delete the standard library (

    Do you have any idea to solve my probleme?

  • Persik

    Where instead of him I wrote

    public class FragmentTab1 extends Fragment {
    private ListView listView;
    private WeakReference getSchedTaskWeakRef;
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.fragmenttab1, container, false);
    public void onActivityCreated(Bundle savedInstanceState) {
    listView = (ListView) getView().findViewById(;
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    public void onItemClick(AdapterView parent, View view, int position,long id) {
    String tab = ((TextView)view.findViewById(;
    Intent i = new Intent (getActivity(),NameActivity.class);
    i.putExtra(NameActivity.TAB_NAME, tab);
    startActivity(i); }
    private void startNewAsyncTask() {
    Calendar calendar = Calendar.getInstance();
    int day = calendar.get(Calendar.DAY_OF_WEEK);
    String weekType;
    if (day==1 || day ==7) {
    weekType=”we”; }
    String timeNow = (new SimpleDateFormat(“HH:mm”).format(calendar.getTime()));
    GetSchedAsyncTask asyncTask = new GetSchedAsyncTask(this);
    this.getSchedTaskWeakRef = new WeakReference(asyncTask);
    private class GetSchedAsyncTask extends AsyncTask<Object, Void, List> {
    private WeakReference fragmentWeakRef;
    private GetSchedAsyncTask (FragmentTab1 fragment) {
    this.fragmentWeakRef = new WeakReference(fragment);
    protected List doInBackground(Object… params) {
    MetroDatabase db = MetroDatabase.getInstance(getActivity());
    List schedule = db.getSchedule((String) params[0], (String) params[1]);
    return schedule;
    protected void onPostExecute(List schedule) {
    if (this.fragmentWeakRef.get() != null) {
    listView.setAdapter(new ScheduleListAdapter(getActivity(), R.layout.name_row_item, schedule));
    } } } }
    I wrote everything it is correct and without errors. Produce an emulator shows nothing and in 5 seconds gives out an error “Unfortunately,… has stopped”. Does can I not correctly wrote or somewhere there is an error?

  • hemant shori

    thank you man you saved my day .thx respect…..!

  • Subashini P

    Thanks for the tutorial.. its very helpful…

  • Ibrahim Ahmed Alshareif

    hello can you tell me how i can use the onbackpressed method in FragmentTab1 i tried
    thanx you

  • safiely


  • Marcos Santos

    Very nice!

    But the action bar does not appear in fragmentTabs 1, how can I solve this?

  • Abhishek Malhotra

    is there a mechanism by which I can shift the Tab1 and Tab2 to the left of the screen currently Tab1 appears in the middle.

  • Ramachandra Bhagwat

    When back button is pressed from Tab2 it wont go to Tab1.Any solution?

  • Gaurav Mandlik


    it’s good tutorial

    i have a issue on adding in multiple fragment can u please help me ???

    your code is run perfectly when i use two fragment but when i add a more fragment on list view item it will mismatch or did not open proper fragment,

    code is :

    title = new String[] { “Download Any Mp3”, “Profile”, “Search”,”About”, };

    subtitle = new String[] { “Download Song”, “Edit”, “History Search”,”Contact Us”};

    icon = new int[] { R.drawable.action_about, R.drawable.action_about,R.drawable.action_about, R.drawable.action_about}

    mMenuAdapter = new MenuListAdapter(MainActivity.this, title, subtitle,

    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();

    // Locate Position

    switch (position) {

    case 0:

    Fragment fragment2 = new SongMainFragment();

    ft.replace(, fragment2);


    case 1:

    Fragment fragment1 = new UserProfileFragment();

    ft.replace(, fragment1);

    case 2:

    Fragment fragment3 = new SearchHistoryFragment();

    ft.replace(, fragment3);



    please help me.]


  • Kamiko Hime

    I like that you embedded discuss on here. clever thought