publicObjectinstantiateItem(ViewGroupcontainer,intposition){if(mCurTransaction==null){mCurTransaction=mFragmentManager.beginTransaction();}finallongitemId=getItemId(position);// Do we already have this fragment?Stringname=makeFragmentName(container.getId(),itemId);Fragmentfragment=mFragmentManager.findFragmentByTag(name);if(fragment!=null){if(DEBUG)Log.v(TAG,"Attaching item #"+itemId+": f="+fragment);mCurTransaction.attach(fragment);}else{fragment=getItem(position);if(DEBUG)Log.v(TAG,"Adding item #"+itemId+": f="+fragment);mCurTransaction.add(container.getId(),fragment,makeFragmentName(container.getId(),itemId));}if(fragment!=mCurrentPrimaryItem){fragment.setMenuVisibility(false);fragment.setUserVisibleHint(false);}returnfragment;}
publicObjectinstantiateItem(ViewGroupcontainer,intposition){// If we already have this item instantiated, there is nothing// to do. This can happen when we are restoring the entire pager// from its saved state, where the fragment manager has already// taken care of restoring the fragments we previously had instantiated.if(mFragments.size()>position){Fragmentf=mFragments.get(position);if(f!=null){returnf;}}if(mCurTransaction==null){mCurTransaction=mFragmentManager.beginTransaction();}Fragmentfragment=getItem(position);if(DEBUG)Log.v(TAG,"Adding item #"+position+": f="+fragment);if(mSavedState.size()>position){Fragment.SavedStatefss=mSavedState.get(position);if(fss!=null){fragment.setInitialSavedState(fss);}}while(mFragments.size()<=position){mFragments.add(null);}fragment.setMenuVisibility(false);fragment.setUserVisibleHint(false);mFragments.set(position,fragment);mCurTransaction.add(container.getId(),fragment);returnfragment;}