Example usage for android.app FragmentTransaction replace

List of usage examples for android.app FragmentTransaction replace

Introduction

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

Prototype

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

Source Link

Document

Replace an existing fragment that was added to a container.

Usage

From source file:com.sintef_energy.ubisolar.activities.DrawerActivity.java

/**
 * Helper method to add fragments to the view.
 *
 * @param fragment Fragment to swap in// w  ww  . java2  s  .c  o  m
 * @param animate True if swap shall have an animation
 * @param addToBackStack True if the Fragment shall go to the back stack
 * @param tag String for the back stack
 */
public void addFragment(Fragment fragment, boolean animate, boolean addToBackStack, String tag) {
    FragmentManager manager = getFragmentManager();

    FragmentTransaction ft = manager.beginTransaction();
    if (animate) {
        ft.setCustomAnimations(android.R.anim.slide_in_left, android.R.anim.slide_out_right,
                // Pop enter
                android.R.anim.fade_in, android.R.anim.fade_out);
    }

    if (addToBackStack) {
        ft.addToBackStack(tag);
    }

    ft.replace(R.id.container, fragment, tag);
    ft.commit();
}

From source file:com.nuvolect.securesuite.main.ContactListActivity.java

private void startContactEditFragment() {

    if (mTwoPane) {
        ContactEditFragment fragment = new ContactEditFragment();
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.replace(R.id.contact_detail_container, fragment, CConst.CONTACT_EDIT_FRAGMENT_TAG);
        ft.commit();/*from   w  ww  .  j a v a2  s  . com*/
    } else {

        Intent i = new Intent(getApplicationContext(), ContactEditActivity.class);
        startActivity(i);
    }
}

From source file:com.nuvolect.securesuite.main.ContactListActivity.java

private void startContactDetailFragment() {

    if (mTwoPane) {
        ContactDetailFragment frag = new ContactDetailFragment();
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.replace(R.id.contact_detail_container, frag, CConst.CONTACT_DETAIL_FRAGMENT_TAG);
        ft.commit();/*from  ww  w.  ja v a2 s. com*/
    } else {

        Intent i = new Intent(getApplicationContext(), ContactDetailActivity.class);
        startActivity(i);
    }
}

From source file:com.nuvolect.securesuite.main.ContactListActivity.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private ContactListFragment startContactListFragment() {

    boolean isDestroyed = false;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && m_act.isDestroyed())
        isDestroyed = true;//from   w w w  . j ava 2s .  c om

    if (m_act == null || isDestroyed || m_act.isFinishing())
        return null;

    ContactListFragment clf = new ContactListFragment();
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    ft.replace(R.id.contact_list_container, clf, CConst.CONTACT_LIST_FRAGMENT_TAG);
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
    ft.addToBackStack(null);
    ft.commit();
    return clf;
}

From source file:com.mobile.syslogng.monitor.MainActivity.java

public void setFragment(Fragment fragment, Integer position, String tag) {

    updateDrawer(position);/* w  w  w  .j av a 2 s . c o  m*/
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction transaction = fragmentManager.beginTransaction();
    Bundle args = new Bundle();
    args.putInt(MainActivity.FRAGMENT_POS, position);
    fragment.setArguments(args);
    String cTag = "empty";
    Fragment currentFragment = fragmentManager.findFragmentById(R.id.container);
    if (currentFragment != null) {
        cTag = currentFragment.getTag();
        if (!cTag.equals(tag)) {
            if (currentFragment instanceof WelcomeFragment
                    || currentFragment instanceof MonitoredSyslogngFragment
                    || currentFragment instanceof AboutFragment) {
                stackCount = 0;
                transaction.addToBackStack(cTag);
                stackCount++;
            } else {
                if (stackCount < 2) {
                    transaction.addToBackStack(cTag);
                    stackCount++;
                }
            }
        }
    }
    transaction.replace(R.id.container, fragment, tag).commit();
}

From source file:com.example.search.car.pools.welcome.java

private void set_fragment(Fragment fragment) {
    // TODO Auto-generated method stub
    FragmentManager fm = getFragmentManager();
    FragmentTransaction fragmentTransaction = fm.beginTransaction();
    fragmentTransaction.replace(R.id.content_frame, fragment, frag_tag);
    fragmentTransaction.commit();//from w ww.  j  av a2  s. c om
}

From source file:com.example.search.car.pools.welcome.java

private void selectItem(int position) {
    setTitle(mPlanetTitles[position]);//  w ww.j av a  2s  .co m

    // update the main content by replacing fragments
    Fragment fragment = null;
    if (mPlanetTitles[position].equals("Cities")) {
        layout = "Cities";
        fragment = new Cities();
        frag_tag = "Cities";

        // } else if (mPlanetTitles[position].equals("Promote Carpooling"))
        // {
        // layout = "Promote Carpooling";
        // fragment = new Promote_Carpooling();
        // frag_tag = "Promote Carpooling";
        // } else if (mPlanetTitles[position].equals("Create Listing")) {
        // layout = "Create Listing";
        // fragment = new Create_Listing();
        // frag_id = 3;
        // frag_tag = "Create Listing";
        // } else if (mPlanetTitles[position].equals("About Us")) {
        // layout = "About Us";
        // fragment = new About_Us();
        //
        // } else if (mPlanetTitles[position].equals("Blog")) {
        // layout = "Blog";
        // fragment = new blog();

    } else if (mPlanetTitles[position].equals("Dashboard")) {
        layout = "Dashboard";
        fragment = new dashboard();
        frag_tag = "Dashboard";
        // getActionBar().setTitle("My Profile");
    } else {
        layout = "Search";
        frag_tag = "Search";
        fragment = new Search();
    }

    FragmentManager fm = getFragmentManager();
    FragmentTransaction fragmentTransaction = fm.beginTransaction();
    fragmentTransaction.replace(R.id.content_frame, fragment, frag_tag);
    fragmentTransaction.commit();
    /*
     * Bundle args = new Bundle();
     * args.putInt(PlanetFragment.ARG_PLANET_NUMBER, position);
     * fragment.setArguments(args);
     * 
     * FragmentManager fragmentManager = getFragmentManager();
     * fragmentManager.beginTransaction().replace(R.id.content_frame,
     * fragment).commit();
     */
    // update selected item and title, then close the drawer
    // mDrawerList.setItemChecked(position, true);

    mDrawerLayout.closeDrawer(mDrawerList);

}

From source file:it.scoppelletti.mobilepower.app.FragmentLayoutController.java

/**
 * Ricostruisce la successione della disposizione dei frammenti nei
 * pannelli./*from  ww  w .jav a  2s  .  com*/
 * 
 * @param  fragmentMgr   Gestore dei frammenti.
 * @param  fragmentQueue Frammenti.
 * @return               Identificatore dell&rsquo;ultimo elemento inserito
 *                       nel back stack.
 */
private int arrangeFragments(FragmentManager fragmentMgr,
        Queue<FragmentLayoutController.FragmentEntry> fragmentQueue) {
    int i;
    int frameCount, tnId, lastTnId;
    FragmentLayoutController.FragmentEntry entry;
    FragmentSupport newFragment, oldFragment;
    FragmentLayoutController.FragmentEntry[] frames;
    FragmentTransaction fragmentTn = null;

    frameCount = 1;
    frames = new FragmentLayoutController.FragmentEntry[myFrameCount];
    Arrays.fill(frames, null);

    lastTnId = -1;
    while (!fragmentQueue.isEmpty()) {
        tnId = -1;
        entry = fragmentQueue.remove();

        try {
            fragmentTn = fragmentMgr.beginTransaction();

            if (frameCount == myFrameCount) {
                // Tutti i pannelli sono occupati:
                // Sposto ogni frammento nel pannello precedente per
                // liberare l'ultimo.
                for (i = 0; i < frameCount; i++) {
                    if (frames[i] == null) {
                        // Inizialmente il primo pannello risulta vuoto
                        // anche se in realta' e' occupato dal frammento
                        // principale (non di dettaglio).
                        continue;
                    }

                    oldFragment = frames[i].getFragment();
                    newFragment = (i > 0) ? oldFragment.cloneFragment() : null;
                    fragmentTn.remove(oldFragment.asFragment());
                    frames[i] = null;

                    if (newFragment != null) {
                        fragmentTn.replace(myFrameIds[i - 1], newFragment.asFragment(), entry.getTag());
                        frames[i - 1] = new FragmentLayoutController.FragmentEntry(newFragment, entry.getTag());
                    }
                }

                frameCount--;
            }

            fragmentTn.add(myFrameIds[frameCount], entry.getFragment().asFragment(), entry.getTag());
            frames[frameCount++] = entry;

            fragmentTn.addToBackStack(null);
        } finally {
            if (fragmentTn != null) {
                tnId = fragmentTn.commit();
                fragmentTn = null;
            }
        }

        if (tnId >= 0) {
            lastTnId = tnId;
        }
    }

    return lastTnId;
}

From source file:com.mods.grx.settings.GrxSettingsActivity.java

public void chage_to_screen_to_sync() {
    if (mNumSyncScreens < ResXML.size()) {
        android.app.FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
        GrxPreferenceScreen prefsScreen = GrxPreferenceScreen.newInstance(ResXML.get(mNumSyncScreens), "", "",
                0);//www.j  ava  2  s  .  c o  m
        fragmentTransaction.replace(R.id.content, prefsScreen, Common.TAG_PREFSSCREEN_FRAGMENT_SYNC).commit();
    } else
        finish_sync();
}

From source file:com.concentricsky.android.khanacademy.app.VideoDetailActivity.java

private void setupUIForCurrentVideo() {
    if (videoFragment != null) {
        videoFragment.dispose();/* w  w  w . ja  va2 s .  com*/
    }

    Bundle args = new Bundle();
    args.putString(Constants.PARAM_VIDEO_ID, videoId);

    videoFragment = new VideoFragment();
    videoFragment.registerCallbacks(this);
    videoFragment.setArguments(args);

    FragmentTransaction tx = getFragmentManager().beginTransaction().replace(R.id.video_fragment_container,
            videoFragment, TAG_VIDEO_FRAGMENT);

    currentOrientation = getResources().getConfiguration().orientation;
    onOrientationChanged(currentOrientation);

    if (isPortrait()) {
        captionFragment = new CaptionFragment();
        captionFragment.registerCallbacks(this);
        if (userVideo != null && userVideo.getUser() != null) {
            args.putInt(PARAM_USERVIDEO_POINTS, userVideo.getPoints());
        }
        captionFragment.setArguments(args);

        tx.replace(R.id.detail_bottom_container, captionFragment, TAG_CAPTION_FRAGMENT);
    }

    tx.commit();
}