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 8663935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:07:01+00:00 2026-06-12T17:07:01+00:00

I’ve implemented the ActionbarSherlock’s example com.actionbarsherlock.sample.fragments and all works well until the device orientation

  • 0

I’ve implemented the ActionbarSherlock’s example com.actionbarsherlock.sample.fragments and all works well until the device orientation is changed when the selected tab has child fragments.

All good:

Tab1 -> Fragment1

Tab2 -> Fragment2

Tab3 -> Fragment3

All is good and can rotate device without problems. Now if I select a list item in Fragment2 to push Fragment2Child1, all is still good until I rotate the device.

Not good when device rotated:

Tab1 -> Fragment1

Tab2 -> Fragment2 -> Fragment2Child1

Tab3 -> Fragment3

At this point the tabs and fragments are recreated but Fragment2 is displayed under Fragment2Child1. It gets worse when you select another tab, at that point Fragment2 is detached but Fragment2Child1 is displayed under the newly selected tab fragment. I sort of understand the mechanics here but I can’t work out how to not attach Fragment2 after rotation and then detaching Fragment2Child1 (or any fragment for that matter) when another tab is selected.

from MainFragment which extends SherlockFragmentActivity

…

int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if (currentapiVersion >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) {

            mTabManager.addTab(mTabHost.newTabSpec("new").setIndicator(getString(R.string.new_)), NewListSupportActivity.NewListFragment.class, null);
        mTabManager.addTab(mTabHost.newTabSpec("project").setIndicator(getString(R.string.project)), ProjectSupportActivity.ProjectListFragment.class, null);
        mTabManager.addTab(mTabHost.newTabSpec("setting").setIndicator(getString(R.string.settings)), SettingSupportActivity.SettingListFragment.class, null);

        if (savedInstanceState != null) {
            mTabHost.setCurrentTabByTag(savedInstanceState.getString("tab"));
        }

    } else {

…

From the TabManager class

public void addTab(TabHost.TabSpec tabSpec, Class<?> clss, Bundle args) {

    tabSpec.setContent(new DummyTabFactory(this.mActivity));
    final String tag = tabSpec.getTag();

    final TabInfo info = new TabInfo(tag, clss, args);

    // Check to see if we already have a fragment for this tab, probably
    // from a previously saved state. If so, deactivate it, because our
    // initial state is that a tab isn't shown.
    info.fragment = this.mActivity.getSupportFragmentManager().findFragmentByTag(tag);
    if (info.fragment != null && !info.fragment.isDetached()) {
        final FragmentTransaction ft = this.mActivity.getSupportFragmentManager().beginTransaction();
        ft.detach(info.fragment);
        ft.commit();
    }

    this.mTabs.put(tag, info);
    this.mTabHost.addTab(tabSpec);
}

@Override
public void onTabChanged(String tabId) {

    TabInfo newTab = mTabs.get(tabId);
    if (mLastTab != newTab) {
        FragmentTransaction ft = mActivity.getSupportFragmentManager().beginTransaction();
        if (mLastTab != null) {
            if (mLastTab.fragment != null) {
                ft.detach(mLastTab.fragment);
            }
        }
        if (newTab != null) {
            if (newTab.fragment == null) {
                newTab.fragment = Fragment.instantiate(mActivity, newTab.clss.getName(), newTab.args);
                ft.add(mContainerId, newTab.fragment, newTab.tag);
            } else {
                ft.attach(newTab.fragment);
            }
        }

        mLastTab = newTab;
        ft.commit();
        mActivity.getSupportFragmentManager().executePendingTransactions();
    }
}

And the code that pushes Fragment2Child1 or any child for that matter

public void pushFragment(TradiesFragment current, TradiesFragment fragment) {

    fragment.setFragmentListener(this);
    final FragmentManager fm = this.fragment.getFragmentManager();
    final FragmentTransaction ft = fm.beginTransaction();
    ft.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left, android.R.anim.slide_in_left, android.R.anim.slide_out_right);
    ft.detach(current);
    ft.add(this.fragment.getId(), fragment);
    ft.addToBackStack(null);
    ft.commit();
}
  • 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-12T17:07:02+00:00Added an answer on June 12, 2026 at 5:07 pm

    There was no answer to this problem. At least none that I could think of that wasn’t downright ugly. The solution was to wrap the Fragment2Child1 in an Activity. You do end up hiding the tab activity when navigating to Fragment2Child1Activity. And users are forced to navigate back to the main activity (with tabs) every time. On the up-side it actually makes for a simpler UI.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
i got an object with contents of html markup in it, for example: string
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.