在FragmentPagerAdapter中重写以下方法:
1 @Override 2 public Object instantiateItem(ViewGroup container, int position) { 3 Fragment fragment = (Fragment) super.instantiateItem(container, position); 4 fm.beginTransaction().show(fragment).commit(); 5 6 return fragment; 7 } 8 9 @Override 10 public void destroyItem(ViewGroup container, int position, Object object) { 11 Fragment fragment = (Fragment) object; 12 fm.beginTransaction().hide(fragment).commit(); 13 }
时间: 2024-10-12 12:20:39