[Android Pro] fragment has multiple fragment in nested Viewpager,vierpager, does not display

Source: Internet
Author: User
Tags switches

Referece to:http://blog.csdn.net/mybook1122/article/details/24003343

Many applications are now popular for a layout. There are several toolbar options at the bottom, which also have tab-like options.


The bottom uses Radiogroup to control the fragment switch. The above has five fragment.

The first fragment, represents the home page. The home is another tab-like fragment, using Viewpager to switch two fragment.


private void Initviewpager (View parentview) {
Mpager = (Viewpager) Parentview.findviewbyid (R.id.vpager);
Fragmentslist = new arraylist<fragment> ();


Fragment1 = new Sorthotfragment ();
Fragment2 = new Sortnewfragment ();


Fragmentslist.add (FRAGMENT1);
Fragmentslist.add (Fragment2);

Mpager.setadapter (New Myfragmentpageradapter (getactivity (). Getsupportfragmentmanager (), fragmentsList)) ;
Mpager.setcurrentitem (0);
Mpager.setonpagechangelistener (New Myonpagechangelistener ());
}


Generally according to the usual experience, if you want to pass in Fragmentmanager, is the red font part.

However, this can cause a problem: data loss.

When the fragment switches back and forth, the data inside the other single fragment is not lost, and fragment with multiple fragment switches using Viewpager darkness.


Workaround:

Replace the red font section with Getchildfragmentmanager ().

Mpager.setadapter (New Myfragmentpageradapter (getactivity () Getchildfragmentmanager (), fragmentslist));
Mpager.setcurrentitem (0);
Mpager.setonpagechangelistener (New Myonpagechangelistener ());


Before has been busy, only to find a lot of users message request code, very sorry. Now write a simple demo that will now be posted below.

: http://download.csdn.net/download/mybook1122/7657137


[Android Pro] fragment has multiple fragment in nested Viewpager,vierpager, does not display

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.