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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:11:43+00:00 2026-06-14T13:11:43+00:00

I have an app using SlidingMenu, Action Bar Sherlock and now I am trying

  • 0

I have an app using SlidingMenu, Action Bar Sherlock and now I am trying to rewrite my previous code to using the nested fragments introduced in support lib with the release of Android 4.2.

The problem is that when I swipe through the fragments, they are visible for a split second and then they disappear (black screen). Sometimes they stay on screen, and sometimes the screen is entirely black and the fragment doesn’t appear at all. I suspect I have a lack of understanding of the fragment lifecycle, but I really can’t see the error here.

Swiping through them gets me different results. On initial load the first fragment is black. If I swipe to nr 4 and back to nr 1, then nr 1 fragment is OK. If I swipe fast to nr 2 and then to nr 1, the nr 1 is black again. If I swipe slowly from nr 2 to nr 1, then nr 1 stays OK :-/

Here is my code:

public class LeagueInfoFragment extends SherlockFragment {
...
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    if (container != null) {
        container.removeAllViews();
    }
    setRetainInstance(true);
    setHasOptionsMenu(true);
    mExampleId = getArguments().getInt("mExampleId");

    View view = inflater.inflate(R.layout.viewpager_tournament, container,
            false);
    ViewPager awesomePager = (ViewPager) view.findViewById(R.id.pager);
    awesomePager.setAdapter(new ExamplePagerAdapter(this, getChildFragmentManager(), createFragments()));

    TabPageIndicator titleIndicator = (TabPageIndicator) view
            .findViewById(R.id.titles);
    titleIndicator.setViewPager(awesomePager);

    return view;
}

private List<Fragment> createFragments() {
        List<Fragment> list = new ArrayList<Fragment>();
        list.add(LeagueTableFragment.newInstance(0));
        list.add(FixturesFragment.newInstance(1));
        list.add(NewsFragment.newInstance(2));
        list.add(TopscorerFragment.newInstance(3));
        return list;    
}

private class ExamplePagerAdapter extends FragmentPagerAdapter {
    String[] pages;

    LeagueInfoFragment _activity;
    List<Fragment> fragments;
    private ExamplePagerAdapter(LeagueInfoFragment a,
            FragmentManager fragManager, List<Fragment> frags) {
        super(fragManager);
        this.fragments = frags;
        _activity = a;
        pages = new String[] { _activity.getString(R.string.table),
                _activity.getString(R.string.fixtures),
                _activity.getString(R.string.news),
                _activity.getString(R.string.top_scorers) };
    }

    @Override
    public int getCount() {
        return fragments.size();
    }

    @Override
    public Fragment getItem(int arg0) {
        return fragments.get(arg0);         
    }

    public String getPageTitle(int position) {
        return pages[position];
    }
}

And here is one of my fragments (simplified to reduce code posted here):

public class NewsFragment extends SherlockFragment implements IAsynchData
{   
public static NewsFragment newInstance(int notUsed) {
    NewsFragment f = new NewsFragment();
    return f;
}

@Override
public View onCreateView(android.view.LayoutInflater inflater,
    ViewGroup container, Bundle savedInstanceState) {
    if (container != null) {
        container.removeAllViews();
    }
    View view = inflater.inflate(R.layout.fragment_news, container,
            false);
            //Code left out to load the URL in the webview
    updateRssFeed("http://www.sportspage.com/myteam");
    return view;
}   

}

  • 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-14T13:11:44+00:00Added an answer on June 14, 2026 at 1:11 pm

    Sorry, but why are you doing this while onCreateView in Fragment:

    if (container != null) {
            container.removeAllViews();
    }
    

    As I know, in this moment, container is your ViewPager and removeAllViews() – remove all created View of your Fragments in ViewPager.

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

Sidebar

Related Questions

I have a silverlight app using Prism practices; the current code does a search
I have an iphone app using ASIHttpRequest. The server code is on heroku in
I have an app using a tab bar host api that I found and
I have a rails app using postgres and hosting on heroku. I 'm trying
I have an app using a tab bar and, when the app loads, I
I have an app using fragments, all of which are contained in a single
I have an app using a ListView as a main screen. Each row displays
I have an app using SQLite3. It's running pretty well, but I would like
I have an app using the ADO.NET entity framework (the VS2008 version, not the
I have an App using UITableViews and fetching data from a server. I am

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.