安卓源码学习笔记

pipidi

zhujingdi1998@gmail.com

安卓fragment源码全解析

创建fragment

BlankFragment b = new  BlankFragment();
                android.app.FragmentManager fm = getFragmentManager();
                FragmentTransaction ft=fm.beginTransaction();
                ft.replace(R.id.rootView,b);
                 ft.commit();

返回一个FragmentManager实例

/**
     * Return the FragmentManager for interacting with fragments associated
     * with this activity.
     */
    public FragmentManager getFragmentManager() {
        return mFragments.getFragmentManager();
    }

mFragmentcreateController创建的一个对象

final FragmentController mFragments = FragmentController.createController(new HostCallbacks());

可以看出hostCallBackFragmentHostCallback的子类

private final FragmentHostCallback<?> mHost;

    /**
     * Returns a {@link FragmentController}.
     */
    public static final FragmentController createController(FragmentHostCallback<?> callbacks) {
        return new FragmentController(callbacks);
    }

    private FragmentController(FragmentHostCallback<?> callbacks) {
        //FragmentController的构造函数是
        mHost = callbacks;
    }

阅读量