/** * 设置Fragment切换不从新创建 */ private Fragment mContent=null; public void switchContent(Fragment from, Fragment to) { if (mContent != to) { mContent = to; FragmentTransaction transaction = manager.beginTransaction(); if (!to.isAdded()) { // 先判断是否被add过 transaction.hide(from).add(R.id.fragment_goods_room, to).commit(); // 隐藏当前的fragment,add下一个到Activity中 } else { transaction.hide(from).show(to).commit(); // 隐藏当前的fragment,显示下一个 } } }
设置Fragment切换不从新创建
最新推荐文章于 2021-05-29 00:39:11 发布