// 初始化默认显示的界面 if (purchaserHomeFragment == null) { purchaserHomeFragment = new PurchaserHomeFragment(); addFragment(purchaserHomeFragment); showFragment(purchaserHomeFragment); } else { showFragment(purchaserHomeFragment); } // 购物车界面 if (purchaserCarFragment == null) { purchaserCarFragment = new PurchaserCarFragment(); // 判断当前界面是否隐藏,如果隐藏就进行添加显示,false表示显示,true表示当前界面隐藏 if (!purchaserCarFragment.isHidden()) { addFragment(purchaserCarFragment); showFragment(purchaserCarFragment); } } else { if (purchaserCarFragment.isHidden()) { showFragment(purchaserCarFragment); } } /** 添加fragment **/ public void addFragment(Fragment fragment) { FragmentTransaction ft = this.getSupportFragmentManager().beginTransaction(); ft.add(R.id.fl_content, fragment); ft.commit(); } /** 显示fragment **/ public void showFragment(Fragment fragment) { FragmentTransaction ft = this.getSupportFragmentManager().beginTransaction(); // 判断页面是否已经创建,如果已经创建,那么就隐藏掉 if (purchaserHomeFragment != null) { ft.hide(purchaserHomeFragment); } if (purchaserTypeFragment != null) { ft.hide(purchaserTypeFragment); } if (purchaserOrderFragment != null) { ft.hide(purchaserOrderFragment); } if (purchaserCarFragment != null) { ft.hide(purchaserCarFragment); } ft.show(fragment); ft.commitAllowingStateLoss(); }
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。