1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
| public class MainActivity extends AppCompatActivity { private Fragment mBeforeFragment; private Fragment mFragment;
public void change2FirstFragment() { FirstFragment fragment = (FirstFragment) getSupportFragmentManager().findFragmentByTag("FirstFragment"); if (fragment == null) { fragment = FirstFragment.newInstance(this); Bundle bundle = new Bundle(); bundle.putString("time", DateUtil.getCurrentTime()); fragment.setArguments(bundle); FragmentUtil.addFragment(getSupportFragmentManager(), R.id.fragment, mFragment, fragment, "FirstFragment"); } else { if (mFragment != fragment) { FragmentUtil.showFragment(getSupportFragmentManager(), mFragment, fragment); } fragment.update(DateUtil.getCurrentTime()); } mBeforeFragment = null; mFragment = fragment; }
public void change2SecondFragment() { SecondFragment fragment = (SecondFragment) getSupportFragmentManager().findFragmentByTag("SecondFragment"); if (fragment == null) { fragment = SecondFragment.newInstance(this); Bundle bundle = new Bundle(); bundle.putString("time", DateUtil.getCurrentTime()); fragment.setArguments(bundle); FragmentUtil.addFragment(getSupportFragmentManager(), R.id.fragment, mFragment, fragment, "SecondFragment"); } else { if (mFragment != fragment) { FragmentUtil.showFragment(getSupportFragmentManager(), mFragment, fragment); } fragment.update(DateUtil.getCurrentTime()); } mBeforeFragment = mFragment; mFragment = fragment; }
public void change2ThirdFragment() { ThirdFragment fragment = (ThirdFragment) getSupportFragmentManager().findFragmentByTag("ThirdFragment"); if (fragment == null) { fragment = ThirdFragment.newInstance(this); Bundle bundle = new Bundle(); bundle.putString("time", DateUtil.getCurrentTime()); fragment.setArguments(bundle); FragmentUtil.addFragment(getSupportFragmentManager(), R.id.fragment, mFragment, fragment, "ThirdFragment"); } else { if (mFragment != fragment) { FragmentUtil.showFragment(getSupportFragmentManager(), mFragment, fragment); } fragment.update(DateUtil.getCurrentTime()); } mBeforeFragment = null; mFragment = fragment; }
public void change2FourthFragment() { FourthFragment fragment = (FourthFragment) getSupportFragmentManager().findFragmentByTag("FourthFragment"); if (fragment == null) { fragment = FourthFragment.newInstance(this); Bundle bundle = new Bundle(); bundle.putString("time", DateUtil.getCurrentTime()); fragment.setArguments(bundle); FragmentUtil.addFragment(getSupportFragmentManager(), R.id.fragment, mFragment, fragment, "FourthFragment"); } else { if (mFragment != fragment) { FragmentUtil.showFragment(getSupportFragmentManager(), mFragment, fragment); } fragment.update(DateUtil.getCurrentTime()); } mBeforeFragment = mFragment; mFragment = fragment; } }
|