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.android.tv.settings.dialog.DialogFragment.java

public static void add(FragmentManager fm, DialogFragment f) {
    boolean hasDialog = fm.findFragmentByTag(TAG_LEAN_BACK_DIALOG_FRAGMENT) != null;
    FragmentTransaction ft = fm.beginTransaction();

    if (hasDialog) {
        ft.setCustomAnimations(ANIMATION_FRAGMENT_ENTER, ANIMATION_FRAGMENT_EXIT, ANIMATION_FRAGMENT_ENTER_POP,
                ANIMATION_FRAGMENT_EXIT_POP);
        ft.addToBackStack(null);//from w  w w.  j av a  2s.  c om
    }
    ft.replace(android.R.id.content, f, TAG_LEAN_BACK_DIALOG_FRAGMENT).commit();
}

From source file:leoisasmendi.android.com.suricatepodcast.MainActivity.java

private void initFragments() {
    fragmentManager = getFragmentManager();
    Log.d(TAG, "onCreate: twoPaneMode " + getResources().getBoolean(R.bool.twoPaneMode));
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

    if (getResources().getBoolean(R.bool.twoPaneMode)) {

        fragmentTransaction
                .replace(R.id.master_container, new MainFragment(), MainFragment.class.getSimpleName()).replace(
                        R.id.detail_container, new DetailFragment(), MediaPlayerFragment.class.getSimpleName());

    } else { //Single panel view
        fragmentTransaction.replace(R.id.master_container, new MainFragment(),
                MainFragment.class.getSimpleName());
    }/*from www  .  ja v a  2 s . c  o  m*/

    fragmentTransaction.commit();
}

From source file:com.aokp.romcontrol.github.tasks.DisplayProjectsListTask.java

private void addPropertiesToPreference(PreferenceCategory mProject, JSONObject projectsObject) {
    try {//from w  w w.j av a2 s .  c  o  m
        // extract info about each project
        final String projectName = projectsObject.getString("name");
        String projectDescription = projectsObject.getString("description");
        int githubProjectId = projectsObject.getInt("id");
        // apply info to our preference screen
        mProject.setKey(projectName);
        if (projectDescription.contains("") || projectDescription == null) {
            mProject.setTitle(projectName);
            mProject.setSummary(projectDescription);
        } else {
            mProject.setTitle(projectDescription);
            mProject.setSummary(projectName);
        }
        mProject.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference p) {
                FragmentTransaction transaction = mFragmentManager.beginTransaction();
                CommitsFragment commitFragment = new CommitsFragment(mAlertDialog, projectName);
                transaction.addToBackStack(null);
                transaction.replace(mId, commitFragment, projectName);
                transaction.commit();
                return true;
            }
        });
    } catch (JSONException badJsonRequest) {
        Log.e(TAG, "failed to parse required info about project", badJsonRequest);
    }
}

From source file:com.vaporwarecorp.mirror.feature.main.MirrorActivity.java

private void showMirrorView(final FragmentManager fragmentManager, final MirrorView mirrorView,
        final boolean addToBackStack, final String tag) {
    if (mirrorView.isFullscreen()) {
        mFullscreenContainer.setVisibility(View.VISIBLE);

        final FragmentTransaction transaction = fragmentManager.beginTransaction();
        transaction.replace(getContainerViewId(), (Fragment) mirrorView, tag);
        if (addToBackStack) {
            transaction.addToBackStack(tag);
        }/*w w  w  . ja  v  a2s .  c  o m*/
        transaction.commitAllowingStateLoss();
    } else {
        showFragment(fragmentManager, (Fragment) mirrorView, addToBackStack, tag);
    }
}

From source file:com.vaporwarecorp.mirror.feature.main.MirrorActivity.java

private void showFragment(final FragmentManager fragmentManager, final Fragment fragment,
        final boolean addToBackStack, final String tag) {
    // hide the full screen container
    hideFullScreenView();// ww w.j av a2  s  .  c  o  m

    if (fragmentManager.findFragmentByTag(tag) == null) {
        final int viewId = mContentContainer.addBorderView(this);
        updateCurrentPresenterClass(fragment, viewId);

        final FragmentTransaction transaction = fragmentManager.beginTransaction();
        transaction.replace(viewId, fragment, tag);
        if (addToBackStack) {
            transaction.addToBackStack(tag);
        }
        transaction.commitAllowingStateLoss();
    } else {
        fragmentManager.beginTransaction().detach(fragment).attach(fragment).commitAllowingStateLoss();
    }
}

From source file:com.prasanna.android.stacknetwork.QuestionActivity.java

private void displayPostCommentFragment(String title, long id, int viewPagerPosition, String fragmentTag,
        String defaultText) {/*from w w w  .  jav a2s .c  o m*/
    postCommentFragment = new PostCommentFragment();
    postCommentFragment.setPostId(id);
    postCommentFragment.setViewPagerPosition(viewPagerPosition);
    postCommentFragment.setTitle(title);
    postCommentFragment.setResultReceiver(resultReceiver);

    if (commentsDraft.get(fragmentTag) != null)
        postCommentFragment.setDraftText(commentsDraft.get(fragmentTag));

    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.replace(R.id.fragmentContainer, postCommentFragment, fragmentTag);
    transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    transaction.addToBackStack(fragmentTag);
    transaction.commit();
}

From source file:io.demiseq.jetreader.activities.MainActivity.java

private void GetNewMangas() {
    NewFragment fragment = new NewFragment();
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.replace(R.id.content_frame, fragment, "NEW");
    fragmentTransaction.commit();//ww w  .ja v a2  s .  com
    removeSpinner();
    setTitle(new_);
}

From source file:io.demiseq.jetreader.activities.MainActivity.java

private void GetRecentList() {
    RecentFragment fragment = new RecentFragment();
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.replace(R.id.content_frame, fragment, "RECENT");
    fragmentTransaction.commit();/*  w  w w  . j  a  va2 s  .com*/
    removeSpinner();
    setTitle(recent);
}

From source file:io.demiseq.jetreader.activities.MainActivity.java

private void GetSubscription() {
    SubscriptionFragment fragment = new SubscriptionFragment();
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.replace(R.id.content_frame, fragment, "FEEDS");
    fragmentTransaction.commit();/*  ww  w . j  a va  2 s. c  om*/
    removeSpinner();
    setTitle(feeds);
}

From source file:io.demiseq.jetreader.activities.MainActivity.java

public void GetDownloaded() {
    DownloadedFragment fragment = new DownloadedFragment();
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.replace(R.id.content_frame, fragment, "DOWNLOADED");
    fragmentTransaction.commit();// w w w.j  a  v a  2 s  .co m
    removeSpinner();
    setTitle(downloaded);
}