Example usage for android.app FragmentTransaction add

List of usage examples for android.app FragmentTransaction add

Introduction

In this page you can find the example usage for android.app FragmentTransaction add.

Prototype

public abstract FragmentTransaction add(@IdRes int containerViewId, Fragment fragment, String tag);

Source Link

Document

Add a fragment to the activity state.

Usage

From source file:com.commonsware.android.pagercolumns.MainActivity.java

private void populateColumn(FragmentManager fm, FragmentTransaction ft, SamplePagerAdapter adapter,
        int position, int slot) {
    EditorFragment f = adapter.getExistingFragment(position);

    if (f == null) {
        f = adapter.createFragment(buildTitle(position));
    } else {//from   w w  w.  j a v a 2  s  .c  om
        fm.beginTransaction().remove(f).commit();
        fm.executePendingTransactions();
    }

    ft.add(slot, f, buildTag(position));
}

From source file:org.kymjs.kjframe.KJActivity.java

/**
 * Fragment?//from  w ww. jav  a2s. c  o  m
 *
 * @param resView        ??
 * @param targetFragment ??Fragment
 */
public void changeFragment(int resView, KJFragment targetFragment) {
    if (targetFragment.equals(currentKJFragment)) {
        return;
    }
    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    if (!targetFragment.isAdded()) {
        transaction.add(resView, targetFragment, targetFragment.getClass().getName());
    }
    if (targetFragment.isHidden()) {
        transaction.show(targetFragment);
        targetFragment.onChange();
    }
    if (currentKJFragment != null && currentKJFragment.isVisible()) {
        transaction.hide(currentKJFragment);
    }
    currentKJFragment = targetFragment;
    transaction.commit();
}

From source file:com.esri.android.mapsapp.MapsAppActivity.java

/**
 * Opens the content browser that shows the user's maps.
 *///from  w w  w.  j a  v  a2  s.c  o  m
private void showContentBrowser() {
    FragmentManager fragmentManager = getFragmentManager();
    Fragment browseFragment = fragmentManager.findFragmentByTag(ContentBrowserFragment.TAG);
    if (browseFragment == null) {
        browseFragment = new ContentBrowserFragment();
    }

    if (!browseFragment.isVisible()) {
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        transaction.add(R.id.maps_app_activity_content_frame, browseFragment, ContentBrowserFragment.TAG);
        transaction.addToBackStack(null);
        transaction.commit();

        invalidateOptionsMenu(); // reload the options menu
    }

    mDrawerLayout.closeDrawers();
}

From source file:org.kymjs.kjframe.KJActivity.java

/**
 * Fragment?/*  www.  j  a  v a  2  s. c om*/
 *
 * @param resView        ??
 * @param targetFragment ??Fragment
 * @param isBack  ??true
 */
public void changeFragment(int resView, KJFragment targetFragment, boolean isBack) {
    if (targetFragment.equals(currentKJFragment)) {
        return;
    }
    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    if (!targetFragment.isAdded()) {
        transaction.add(resView, targetFragment, targetFragment.getClass().getName());
    }
    if (targetFragment.isHidden()) {
        transaction.show(targetFragment);
        targetFragment.onChange();
    }
    if (currentKJFragment != null && currentKJFragment.isVisible()) {
        transaction.hide(currentKJFragment);
    }
    if (isBack) {
        transaction.addToBackStack(null);
    }
    currentKJFragment = targetFragment;
    transaction.commit();
}

From source file:org.kymjs.kjframe.KJActivity.java

/**
 * Fragment?// ww w . j  a v  a2s. c  om
 *
 * @param resView        ??
 * @param targetFragment ??Fragment
 * @param isBack  ??true
 */
public void changeFragment(int resView, SupportFragment targetFragment, boolean isBack) {
    if (targetFragment.equals(currentSupportFragment)) {
        return;
    }
    android.support.v4.app.FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    if (!targetFragment.isAdded()) {
        transaction.add(resView, targetFragment, targetFragment.getClass().getName());
    }
    if (targetFragment.isHidden()) {
        transaction.show(targetFragment);
        targetFragment.onChange();
    }
    if (currentSupportFragment != null && currentSupportFragment.isVisible()) {
        transaction.hide(currentSupportFragment);
    }
    if (isBack) {
        transaction.addToBackStack(null);
    }
    currentSupportFragment = targetFragment;
    transaction.commit();
}

From source file:com.mediatek.engineermode.EngineerMode.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);/* w ww.j  a  v a 2s. c  o  m*/

    final FragmentManager fragmentManager = getFragmentManager();
    final FragmentTransaction transaction = fragmentManager.beginTransaction();

    if (isWifiOnly()) {
        TAB_TITLE_IDS = TAB_TITLE_IDS_WIFIONLY;
        TAB_COUNT = TAB_COUNT_WIFIONLY;
    }

    Log.v("@M_" + TAG, "new fregments");
    for (int i = 0; i < TAB_COUNT; i++) {
        mTabs[i] = new PrefsFragment();
        mTabs[i].setResource(i);
        transaction.add(R.id.viewpager, mTabs[i], String.valueOf(i));
        transaction.hide(mTabs[i]);
    }

    ViewPager viewPager;
    PagerTabStrip pagerTabStrip;

    viewPager = (ViewPager) findViewById(R.id.viewpager);
    pagerTabStrip = (PagerTabStrip) findViewById(R.id.pagertitle);
    pagerTabStrip.setTabIndicatorColorResource(android.R.color.holo_blue_light);

    transaction.commitAllowingStateLoss();
    //        fragmentManager.executePendingTransactions();

    mPagerAdapter = new MyPagerAdapter();
    viewPager.setAdapter(mPagerAdapter);
    viewPager.setCurrentItem(0);
}

From source file:com.evandroid.musica.MainLyricActivity.java

private LyricsViewFragment init(FragmentManager fragmentManager, boolean startEmpty) {
    LyricsViewFragment lyricsViewFragment = (LyricsViewFragment) fragmentManager
            .findFragmentByTag(LYRICS_FRAGMENT_TAG);
    if (lyricsViewFragment == null || lyricsViewFragment.isDetached())
        lyricsViewFragment = new LyricsViewFragment();
    lyricsViewFragment.startEmpty(startEmpty);
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    if (!lyricsViewFragment.isAdded()) {
        fragmentTransaction.add(R.id.main_fragment_container, lyricsViewFragment, LYRICS_FRAGMENT_TAG);
    }// w w  w.  ja v  a  2 s  .  com

    Fragment[] activeFragments = getActiveFragments();
    displayedFragment = getDisplayedFragment(activeFragments);

    for (Fragment fragment : activeFragments)
        if (fragment != null) {
            if (fragment != displayedFragment && !fragment.isHidden()) {
                fragmentTransaction.hide(fragment);
                fragment.onHiddenChanged(true);
            } else if (fragment == displayedFragment)
                fragmentTransaction.show(fragment);
        }
    fragmentTransaction.commit();
    return lyricsViewFragment;
}

From source file:es.farfuteam.vncpp.controller.TabListener.java

/**
 * @param tab//from ww w . ja v  a 2s.c  o m
 * @param ft
 * @brief Method called when the tab is selected
 * @details Method called when the tab is selected
 */
@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
    // Check if the fragment is already initialized
    mFragment = mActivity.getFragmentManager().findFragmentByTag(mTag);
    mActivity.getSupportFragmentManager().findFragmentByTag(mTag);
    if (mFragment == null) {
        // If not, instantiate and add it to the activity
        mFragment = Fragment.instantiate(mActivity, mClass.getName());
        //mFragment.setProviderId(mTag); // id for event provider
        setmTransaction(ft);
        ft.add(android.R.id.content, mFragment, mTag);
    } else {
        // If it exists, simply attach it in order to show it
        setmTransaction(ft);
        ft.attach(mFragment);
    }

}

From source file:com.skubit.comics.activities.MainActivity.java

private void showFragment(Fragment targetFragment, String tag, int position) {
    FragmentManager fm = getFragmentManager();
    FragmentTransaction transaction = fm.beginTransaction().setTransition(FragmentTransaction.TRANSIT_NONE);
    hidesFragments(position, transaction);

    Fragment f = fragments[position];//w w w. ja v a  2 s . c om

    if (f == null) {
        addFragmentToCache(targetFragment, tag, position);
        if (isFragmentInCache(tag)) {
            transaction.show(fragments[position]);
        } else {
            transaction.add(R.id.container, fragments[position], tag);
        }
    } else {
        transaction.show(fragments[position]);
    }

    transaction.commitAllowingStateLoss();
}

From source file:ab.util.AbDialogUtil.java

/**
 * ?????View/*from  w  w w. j  a  v  a2s .  c  o  m*/
 * 
 * @param view
 * @return
 */
public static AbSampleDialogFragment showTipsDialog(View view) {
    FragmentActivity activity = (FragmentActivity) view.getContext();
    // Create and show the dialog.
    AbSampleDialogFragment newFragment = AbSampleDialogFragment.newInstance(DialogFragment.STYLE_NO_TITLE,
            android.R.style.Theme_Holo_Light);
    newFragment.setContentView(view);

    FragmentTransaction ft = activity.getFragmentManager().beginTransaction();
    // 
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    // ?,content?fragment,Activity
    ft.add(android.R.id.content, newFragment, mDialogTag).addToBackStack(null).commit();

    return newFragment;
}