Fragment uses PagerSlidingTabStrip to nest the child Fragment to display the problem. pagerslidingtabstrip

Source: Internet
Author: User

Fragment uses PagerSlidingTabStrip to nest the child Fragment to display the problem. pagerslidingtabstrip

The first fragment represents the homepage. The home page is a tab-like fragment. Two fragment entries are switched using viewpager.

 1  private void InitViewPager(View parentView) { 2        mPager = (ViewPager) parentView.findViewById(R.id.vPager); 3        fragmentsList = new ArrayList<Fragment>(); 4  5  6        fragment1 = new SortHotFragment(); 7        fragment2 = new SortNewFragment(); 8  9 10        fragmentsList.add(fragment1);11        fragmentsList.add(fragment2);12        13        mPager.setAdapter(new MyFragmentPagerAdapter(getActivity().getSupportFragmentManager(), fragmentsList));14        mPager.setCurrentItem(0);15        mPager.setOnPageChangeListener(new MyOnPageChangeListener());16  }

Generally, according to the previous experience, if fragmentmanager is to be imported, it is in red.

However, this will cause a problem: data loss.

When the fragment is switched back and forth, the data in the other individual fragment will not be lost, but the fragment that uses multiple fragment Switches of viewpager will be dark.

 

Solution:

Replace the red font with getChildFragmentManager.

mPager.setAdapter(new MyFragmentPagerAdapter(getChildFragmentManager(), fragmentsList));mPager.setCurrentItem(0);mPager.setOnPageChangeListener(new MyOnPageChangeListener());

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.