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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:45:22+00:00 2026-06-10T01:45:22+00:00

I’m working on an App utilizing ActionBarSherlock with navigation tabs and multiple fragments. I

  • 0

I’m working on an App utilizing ActionBarSherlock with navigation tabs and multiple fragments.

I have three navigation tabs each with one or more child views. I also have three option menu items with one or more child views. Everything works fine when I drill down the views within each Tab or option menu. Each initial subview is a ListFragment that calls a detail view or views.

I run into problems when I start switching tabs while in the child views or the option menu fragment. My views start to overlap with the previous view underneath the new view.

Here is my TabListener:

class MyTabsListener implements ActionBar.TabListener {
public SherlockListFragment fragment;

public MyTabsListener(SherlockListFragment fragment) {
    this.fragment = fragment;
}

public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
    ft.replace(android.R.id.content, fragment);
}

public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {      
    ft.remove(fragment);
}

public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
    // Don't care if a tab is reselected, no special handling required
}

Here is my option menu:

   @Override
public boolean onOptionsItemSelected(MenuItem item) {

    // initialize variables
    FragmentManager fm = null;
    FragmentTransaction ft = null;
    ActionBar actionBar = getSupportActionBar();

    // check to see which action item was selected
    switch (item.getItemId()) {
    case android.R.id.home:
        // initialize variables
        fm = this.getSupportFragmentManager();
        ft = fm.beginTransaction();

        if (fm.getBackStackEntryCount() > 0) {

            fm.popBackStack();
            ft.commit();    
        }else {
            actionBar = getSupportActionBar();
            actionBar.setDisplayHomeAsUpEnabled(false);
        }   
        return true;
    case R.id.menuitem_search:
        onSearchRequested();
        return true;
    case R.id.menuitem_contacts:
        ContactListFragment contactListFragment = new ContactListFragment();    
        ft = getSupportFragmentManager().beginTransaction();
        ft.replace(android.R.id.content, contactListFragment);      
        ft.addToBackStack(null);
        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); 
        ft.commit();
        return true;
    case R.id.menuitem_isolation:
        ISOListFragment isoListFragment = new ISOListFragment();    
        ft = getSupportFragmentManager().beginTransaction();
        ft.replace(android.R.id.content, isoListFragment);      
        ft.addToBackStack(null);           
        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); 
        ft.commit();
        return true;
    case R.id.menuitem_water:
        H2OListFragment h2oListFragment = new H2OListFragment();    
        ft = getSupportFragmentManager().beginTransaction();
        ft.replace(android.R.id.content, h2oListFragment);      
        ft.addToBackStack(null);          
        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); 
        ft.commit();
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

I have one MainActivity for all of the fragments. How do you handle the backstack when dealing with drill down child views and ActionBar navigation tabs?? Any help or suggestions would be greatly appreciated!

  • 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-10T01:45:24+00:00Added an answer on June 10, 2026 at 1:45 am

    Here is the solution that worked for me:

    @Override
    public void onBackPressed() {
    
        // initialize variables
        FragmentManager fm = getSupportFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();
    
        // check to see if stack is empty
        if (fm.getBackStackEntryCount() > 0) {          
            fm.popBackStack();
            ft.commit();    
        }
        else {
    
            super.onBackPressed();
        }
        return;
    }
    
    • 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’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 have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into

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.