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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:16:16+00:00 2026-06-03T04:16:16+00:00

I’m trying to get the handle on all the new ActionBar and Fragments API.

  • 0

I’m trying to get the handle on all the new ActionBar and Fragments API.
I have an main activity, and I want it to manage two different tabs.
I’m using the ActionBarSherlock in order to support older version than ICS.

Each tab contains its own Fragment (each one is a subclass of SherlockListFragment)
I got it to work basically nice, but I have a problem that I’m sure that is stupid, but I can’t figure it out yet:

On the first time each Fragment is shown, everything is OK, the list is populated and so the MenuItems in the ActionBar.

But the second time you see a tab (After swicth and switch-back), Neither the list get populated, nor the ActionBar MenuItems.

This is how I’m switching the tabs:

@Override
public void onTabSelected(Tab tab, FragmentTransaction transaction) {
    SherlockListFragment toAttach = // Find the right fragment here...

    if (toAttach != null) {
        if (toAttach.isAdded() == false) {
            transaction.add(R.id.tab_placeholder, toAttach,
                    REMINDER_FRAGMENT_TAG);
        } else {
            transaction.attach(toAttach);
        }
    }
}

And onTabUneselect I’m detaching the Fragment:

@Override
public void onTabUnselected(Tab tab, FragmentTransaction transaction) {
    SherlockListFragment toDetach = // Find the right fragment
    if (toDetach != null) {
        transaction.detach(toDetach);
    }
}

I’m populating the lists and the ActionBar menu in onResume:

@Override
public void onResume() {
    super.onResume();
    setHasOptionsMenu(true);
    fillRemindersList();
}

I also tried it in onStart and onCreateView but it didn’t help…

So what am I missing here?
And if there are others issues in my code that I’m unaware of, please do tell.

Thanks!

EDIT:

I just confirmed that onResume dosen’t get called after I switch tabs, which is definetly wrong since I’m detaching and re-attaching them…
Am I switching tabs the wrong way?

  • 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-03T04:16:17+00:00Added an answer on June 3, 2026 at 4:16 am

    Try using transaction.remove(fragment) in onTabUnselected and transaction.replace in onTabSelected.

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

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I have a text area in my form which accepts all possible characters from
I am trying to loop through a bunch of documents I have to put
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Basically, what I'm trying to create is a page of div tags, each has

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.