Just get started with a project lazy with viewpager+fragment mode, although in the later projects still use Viewpager+fragment. First talk about the problem, a number of times to switch fragment when the page appears blank, just beginning to think that the parameters passed the problem, but also did appear this problem, hand-cheap caused.
For example, according to the incoming tag instantiation, mistakenly put the first data and the second pass the same data. Copy of the wrong, dead and alive can not switch, and then debug to fix:
/**
* Initialize the Newinstance management fragment page and set the current fragment page
*/
public static basefragment newinstance (Context context,string tag) {
Basefragment basefragment = null;
if (textutils.equals (tag, context.getstring (R.STRING.M))) {
if (basefragment==null)
Basefragment = new Fragmenta ();
}else if (textutils.equals (tag, context.getstring (R.STRING.F))) {
if (basefragment==null)
Basefragment = new Fragmentb ();
}else if (textutils.equals (tag, context.getstring (R.STRING.G))) {
if (basefragment==null)
Basefragment = new Fragmentc ();
}
return basefragment;
}
=================================
Later, the problem manifested in, the first fragment load data slowly in the not loaded when the time to switch other pages when the blank, in the Internet to find a variety of methods just started to think that the cache did not do a good job (did not have time to do the optimization of the cache), and later read a variety of posts, Set the manifest file to Signtask, ... Finally realized that the fragment state was not saved ...
Just add a judgment to the Oncreateview and take care of it:
@Override
Public View Oncreateview (layoutinflater inflater, ViewGroup container,
Bundle savedinstancestate) {
if (MView! = null) {
ViewGroup parent = (ViewGroup) mview.getparent ();
if (parent! = NULL) {
Parent.removeview (MView);
}
return mView;
}
View Rootview = null;
Rootview = Inflater.inflate (R.layout.question, container, false);
MView = Rootview;
return rootview;
}
Activity+fragment multiple switch page blank issue