Code example for FragmentActivity

Methods: fail, getSupportFragmentManager, onCreate, setContentView

0
            this.fragmentClass = fragmentClass;
        } 
 
        @Override 
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            if (getAutoCreateUI()) { 
                setContentToFragment(null); 
            } 
        } 
 
        protected boolean getAutoCreateUI() { 
            return true; 
        } 
 
        void setContentToFragment(T fragment) {
            if (fragment == null) {
                fragment = createFragment();
            } 
 
            LinearLayout layout = new LinearLayout(this);
            layout.setOrientation(LinearLayout.VERTICAL);
            layout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
                    LinearLayout.LayoutParams.FILL_PARENT));
            layout.setId(FRAGMENT_ID);
 
            getSupportFragmentManager().beginTransaction() 
                    .add(FRAGMENT_ID, fragment)
                    .commit(); 
 
            fragmentId = FRAGMENT_ID;
 
            setContentView(layout);
        } 
 
        void setContentToLayout(int i, int fragmentId) {
            this.fragmentId = fragmentId;
            setContentView(i);
        } 
 
        T createFragment() { 
            try { 
                return fragmentClass.newInstance();
            } catch (IllegalAccessException e) {
                fail("could not create fragment"); 
            } catch (InstantiationException e) {
                fail("could not create fragment"); 
            } 
            return null; 
        } 
 
        T getFragment() {