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