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

  • Home
  • SEARCH
  • 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 8576643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:58:15+00:00 2026-06-11T19:58:15+00:00

In my Android app I’m using an Action Bar with tabs to switch between

  • 0

In my Android app I’m using an Action Bar with tabs to switch between fragments that display the content of the tabs. Everything is working fine until an orientation change: Then Android starts to draw the widgets on top of each other so that the contents of the fragments get mixed up. My TabListener:

private class TabListener implements ActionBar.TabListener {
    private final Activity mActivity;
    private final String mTag;

    public TabListener(Activity activity, String tag) {
        mActivity = activity;
        mTag = tag;
    }

    @Override
    public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
        Fragment mFragment = MyActivity.this.getSupportFragmentManager().findFragmentByTag(mTag);
        if (mFragment == null) {
            mFragment = new MyFragment();
            ft.add(android.R.id.content, mFragment, mTag);
        } else {
            ft.attach(mFragment);
        }
    }

    @Override
    public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
        Fragment mFragment = MyActivity.this.getSupportFragmentManager().findFragmentByTag(mTag);
        if (mFragment != null) {
            ft.detach(mFragment);
        }
    }

    @Override
    public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
        // Do nothing
    }
}

The only thing I noticed was that on every orientation change, onTabUnselected() won’t be called, but still onTabSelected() is called (so the current tab will be attached twice without being detached in between). If that’s the problem, I do not know how to fix it. If that’s not the problem, I do not know where to look. I would be glad if someone has a suggestion.

Sidenote: I’m using the Action Bar from ActionBarSherlock. The problem appears on all Android versions I tested with (2.3, 4.0, 4.1).

  • 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-11T19:58:16+00:00Added an answer on June 11, 2026 at 7:58 pm

    I am not sure but here are some steps you can follow

    • Take Bundle reference before your Activity onCreate() method.

      Bundle b1;

    • In your onCreate() method , put the Bundle value in b1

      @Override
      public void onCreate(Bundle savedInstanceState) {b1=savedInstanceState;
      

      ……………………….
      }

    • Use this b1 in your onTabSelected method as

      public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
          Fragment mFragment = MyActivity.this.getSupportFragmentManager().findFragmentByTag(mTag);
      
      
       if (b1!=null){
       ft.detach(mFragment);
      

    //and the rest code

       ................}
            }
    

    Its an conclusion , which I have concluded with my working with fragments, but I have not done it with TabListener. So tell me when you are done , or any other solution.

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

Sidebar

Related Questions

My Android app has a tab bar that uses an Intent to launch the
My Android app, which uses a TabActivity to display its contents, has 4 tabs
My android app requires that the device has an SDcard and that SDcard is
An android app I'm working on relies on a web page for most of
My android-app gets List in the one activity, but activity,that contains the LisView for
My Android app has two Spinners (dropdown menus) working fine. However, now I've added
Every activity within my android app is generated using HTML. When one of the
My Android app has a button that executes this code in order to open
My Android app consists of a simple tablayout (3 tabs). Let's say the user
My android app works on landscape mode. I have a listview that contains some

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.