Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8837839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:49:50+00:00 2026-06-14T09:49:50+00:00

So I have 3 Sherlock Fragments setup and working fine with ViewPageIndicator. What I’d

  • 0

So I have 3 Sherlock Fragments setup and working fine with ViewPageIndicator. What I’d like to do now is put a TabHost inside one of the Fragments so that it displays 2 separate tabs (at the bottom). I believe this means I need to have 2 more Fragments to put inside the 3rd Fragment controlled by the TabHost.

Considering the TabHost needs to be created inside a Fragment, I’m not sure how to properly create it.

Here is the code for the Fragment I’ve gotten working from this tutorial, which I’ve tried to update to add the TabHost unsuccessfully:

TestFragment3.java

public class TestFragment3 extends SherlockFragment {
private String mContent = "none";

public static TestFragment3 newInstance(String text) {
    TestFragment3 fragment = new TestFragment3();

    // Supply num input as an argument.
    Bundle args = new Bundle();
    args.putString(KEY_TAB_NUM, text);
    fragment.setArguments(args);

    return fragment;
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.activity_main, null);
    String text = getString(R.string.tab_page_num) + mContent;
    ((TextView)view.findViewById(R.id.text)).setText(text);

    return view;
}

@Override
public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   mContent =  getArguments() != null ? getArguments().getString(KEY_TAB_NUM) : "none";
}

}

MainActivity.java

public class MainActivity extends SherlockFragmentActivity {

private static final String[] TAB_TITLES = new String[] { "This", "Is", "A", "ViewPager" };

TestFragmentAdapter mAdapter;
    ViewPager mPager;
    PageIndicator mIndicator;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.simple_tabs);

    mAdapter = new TestFragmentAdapter(getSupportFragmentManager());

    mPager = (ViewPager)findViewById(R.id.pager);
    mPager.setAdapter(mAdapter);

    mIndicator = (TabPageIndicator)findViewById(R.id.indicator);
    mIndicator.setViewPager(mPager);
}

class TestFragmentAdapter extends FragmentPagerAdapter {     
    private int mCount = TAB_TITLES.length;

    public TestFragmentAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int position) {
        return TestFragment.newInstance(String.valueOf(position));
    }

    @Override
    public int getCount() {
        return mCount;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return TAB_TITLES[position];
    }
}
}

Do I need to create a new SherlockFragmentActivity and add the 2 additional SherlockFragments to that TabHost? If so, how do I setup the MainActivity with 3 Fragments to use another Activity, not a Fragment, for its 3rd Fragment?

I’m getting this error for trying to put a Fragment within a Fragment…

11-14 19:10:54.271: E/AndroidRuntime(2812): java.lang.IllegalStateException: Recursive entry to executePendingTransactions
11-14 19:10:54.271: E/AndroidRuntime(2812):     at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1388)
11-14 19:10:54.271: E/AndroidRuntime(2812):     at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:431)
11-14 19:10:54.271: E/AndroidRuntime(2812):     at com.example.demolistview.EventInviteesFragment$TabManager.onTabChanged(EventInviteesFragment.java:152)
11-14 19:10:54.271: E/AndroidRuntime(2812):     at android.widget.TabHost.invokeOnTabChangeListener(TabHost.java:391)
11-14 19:10:54.271: E/AndroidRuntime(2812):     at android.widget.TabHost.setCurrentTab(TabHost.java:376)
11-14 19:10:54.271: E/AndroidRuntime(2812):     at android.widget.TabHost.addTab(TabHost.java:236)
...
...
...
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T09:49:51+00:00Added an answer on June 14, 2026 at 9:49 am

    In regards to this question:

    Considering the TabHost needs to be created inside a Fragment, I’m not
    sure how to properly create it.

    If you look at the latest support demos they have an example of what you are trying to implement. They can be downloaded through the SDK Manager.

    This is how they are nesting a tab host within a fragment. The setup is using the Child FragmentManager.

    public class FragmentTabsFragmentSupport extends Fragment {
        private FragmentTabHost mTabHost;
    
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            mTabHost = new FragmentTabHost(getActivity());
            mTabHost.setup(getActivity(), getChildFragmentManager(), R.id.fragment1);
    
            mTabHost.addTab(mTabHost.newTabSpec("simple").setIndicator("Simple"),
                    FragmentStackSupport.CountingFragment.class, null);
            mTabHost.addTab(mTabHost.newTabSpec("contacts").setIndicator("Contacts"),
                    LoaderCursorSupport.CursorLoaderListFragment.class, null);
            mTabHost.addTab(mTabHost.newTabSpec("custom").setIndicator("Custom"),
                    LoaderCustomSupport.AppListFragment.class, null);
            mTabHost.addTab(mTabHost.newTabSpec("throttle").setIndicator("Throttle"),
                    LoaderThrottleSupport.ThrottledLoaderListFragment.class, null);
    
            return mTabHost;
        }
    
        @Override
        public void onDestroyView() {
            super.onDestroyView();
            mTabHost = null;
        }
    }
    

    I also created a small example which can be found at: https://github.com/marsucsb/nested-fragments

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Activity that Displays Fragments one at a time , now each
I have got the same problem for 8 days now and i hope that
I had a couple tabs in the Sherlock ActionBar, and everything was working fine,
I have an Android app that uses ActionBar Sherlock. I create a menu that
I'm trying to figure out how fragments are working. I have 3 classes, MainActivity,
I have a (Sherlock)FragmentActivity with 2 tabbed fragments. The left fragment is a GridView
I have an app using SlidingMenu, Action Bar Sherlock and now I am trying
I have a SherlockFragmentActivity and a SherlockFragment that is within a TabManager. In this
I have application which uses Sherlock ActionBar package. The application uses platform-specific behavior for
Have a procedure which looks like Procedure TestProc(TVar1, TVar2 : variant); Begin TVar1 :=

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.