private Fragment tempFragment;
private BaseFragemt getFragment(int position) {
if(fragments!=null&&fragments.size()>0){
BaseFragemt baseFragemt=fragments.get(position);
return baseFragemt;
}
return null;
}
private void switchFragment(Fragment fromFragment, BaseFragemt nextFragemt) {
if(tempFragment!=nextFragemt){
tempFragment=nextFragemt;
if(nextFragemt!=null){
FragmentTransaction transaction=fragmentManager.beginTransaction();
if(!nextFragemt.isAdded()){
if(fromFragment!=null) {
transaction.hide(fromFragment);
}
transaction.add(R.id.main_page_container, nextFragemt).commit();
}else {
if(fromFragment!=null){
transaction.hide(fromFragment);
}
transaction.show(nextFragemt).commit();
}
}
}
}
Android--Fragment懒加载
最新推荐文章于 2022-10-13 07:08:18 发布