赞
踩
谈到这个问题,首先我不得不说说我原本的耗时又费力还不完美的解决方案。
public FragmentTransaction switchFragment(Fragment targetFragment) { FragmentTransaction transaction = getSupportFragmentManager() .beginTransaction(); if (!targetFragment.isAdded()) { //第一次使用switchFragment()时currentFragment为null,所以要判断一下 if (currentFragment != null) { transaction.hide(currentFragment); } transaction.add(R.id.content_fragment, targetFragment,targetFragment.getClass().getName()); } else { transaction .hide(currentFragment) .show(targetFragment); } currentFragment = targetFragment; return transaction; }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。