Code example for FragmentTransaction

Methods: commit, detach

0
        // initial state is that a tab isn't shown. 
        FragmentManager fm = mActivity.getSupportFragmentManager();
        mFragment = fm.findFragmentByTag(mTag);
        if (mFragment != null && !mFragment.isDetached()) {
            FragmentTransaction ft = fm.beginTransaction();
            ft.detach(mFragment);
            ft.commit();
        } 
    } 
 
    public void onTabSelected(Tab tab, FragmentTransaction unused) {
        // The parameter is always null 
        // See: http://groups.google.com/group/actionbarsherlock/browse_thread/thread/89eac58c13fe1ae0/8d6db0ba248e53d9?show_docid=8d6db0ba248e53d9 
        FragmentManager fm = mActivity.getSupportFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();
        if (mFragment == null) {
            mFragment = Fragment.instantiate(mActivity, mClass.getName(), mArgs);
            ft.add(android.R.id.content, mFragment, mTag);
        } else { 
            ft.attach(mFragment);
        }