import android.support.v4.app.Fragment; import java.util.HashMap; public class FragmentFactory { private static HashMap<Integer, Fragment> savedFragment = new HashMap<Integer, Fragment>(); public static Fragment getFragment(int position) { Fragment fragment = savedFragment.get(position); if (fragment == null) { switch (position) { case 0: fragment = new Fragment01(); break; case 1: fragment = new Fragment02(); break; case 2: fragment = new Fragment03(); break; case 3: fragment = new Fragment04(); break; } savedFragment.put(position, fragment); } return fragment; } }
时间: 2024-10-01 20:41:28