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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:22:26+00:00 2026-06-13T07:22:26+00:00

I’m trying to make a fragment to display tips for the user. The fragment’s

  • 0

I’m trying to make a fragment to display tips for the user. The fragment’s createView method returns a ViewPager and setup the PagerAdapter through AsyncTask. This fragment is added dinamically in the FragmentActivity when the user press a button. If the user reaches the last item of press the same button again, this fragment is removed from the FragmentActivity. It’s important to note that I add the fragment to the FrameLayout idenfified by android.R.id.content.

Ok, the first time I press the button, it works as expected. But the second time I press the button, the ViewPager doesn’t appear. When I use the View Hierarchy to see what’s happenning, I see the ViewPager in the right place, but with no items. I debugged and noted that the getCount() of the PagerAdapter is called, but the getItem is never called.

This is the createView method of my fragment:

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  View tipsView = inflater.inflate(R.layout.tip_manager_layout, container, false);
  this.tipPagerAdapter = new TipPagerAdapter(getFragmentManager(), getArguments().getIntArray(TIP_LAYOUT_IDS_KEY));
  this.viewPager = (ViewPager) tipsView.findViewById(R.id.tip_pager);
  this.viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {  
    @Override
    public void onPageSelected(int position) {
      if(position == (tipPagerAdapter.getCount()-1)){
         stop();
      }
    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }
  });
  // Workaround to set the PagerAdapter within a fragment transaction
  new SetViewPagerAdapterTask().execute();
  return tipsView;
}

I add the fragment this way:

FragmentTransaction fragmentTransaction = fragmentActivity.getSupportFragmentManager().beginTransaction();
fragmentTransaction.add(android.R.id.content, this, TAG);
fragmentTransaction.commit();

And remove the fragment this way:

FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.remove(tipManagerFragment);
fragmentTransaction.commit();

This is the layout inflated by the fragment:

<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tip_pager"
    android:layout_width="fill_parent"
    android:layout_height="175dp"
    android:layout_gravity="center_horizontal|bottom"
    android:paddingBottom="2dp" />

Could someone help me with this problem?

EDIT:

For a while, I’m using the show and hide methods of the fragment after adding it to the activity. But it’s not the correct approach. I can’t understand why I can’t add again a fragment with a ViewPager. The ViewPager is added and removed correctly, but the second time, it simply doesn’t show anything.

  • 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-13T07:22:28+00:00Added an answer on June 13, 2026 at 7:22 am

    After a long time thinking about my problem, I had the following idea: maybe the problem is related to the fact that I’m removing the fragment that has the ViewPager, but I’m not removing the fragments used by the ViewPager. Then, these fragments continues in the FragmentManager and something strange happens when the new ViewPager tries to use them.

    So, I started trying to remove all the fragments. To do this, I created a method in my FragmentPagerAdapter this way:

    public void destroy(FragmentTransaction fragmentTransaction){
        for(Fragment tipFragment : tipFragments){
            fragmentTransaction.remove(tipFragment);
        }
    }
    

    The adapter is using the tipFragments to create its content. So, I get a fragmentTransaction as parameter and I remove all these fragments. When I want to remove my fragment, I use this code:

    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    tipPagerAdapter.destroy(fragmentTransaction);
    fragmentTransaction.remove(TipManagerFragment.this);
    fragmentTransaction.commit();
    

    This way, I remove all the fragments and when I add the fragment which has the ViewPager again, everything works well.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to loop through a bunch of documents I have to put
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to render a haml file in a javascript response like so:
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.