When you use Fragmenttabhost, the Oncreateview method is called each time you switch between fragment, resulting in the layout of each fragment being redrawn and the fragment of the original state cannot be maintained.
Workaround: Cache The view in the fragment Oncreateview method
PrivateView Rootview;//Cache Fragment View@Override PublicView Oncreateview (layoutinflater inflater, ViewGroup container, Bundle savedinstancestate) {if(rootview==NULL) {Rootview=inflater.inflate (R.layout.tab_fragment,NULL); } //The cached Rootview needs to determine if the parent has been added, and if any parent needs to be removed from the parent, the Rootview already has the parent error. ViewGroup parent =(ViewGroup) rootview.getparent (); if(Parent! =NULL) {Parent.removeview (Rootview); } returnRootview; }
Android_ Fragmenttabhost to avoid repeatedly loading the UI when switching fragment