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.lgallardo.qbittorrentclient.RefreshListener.java

@Override
public void onResume() {
    super.onResume();
    activityIsVisible = true;//w ww . j av a  2 s.c om

    // Handle Item list empty due to Fragment stack
    try {

        FragmentManager fm = getFragmentManager();
        FragmentTransaction fragmentTransaction = fm.beginTransaction();

        if (fm.getBackStackEntryCount() == 0 && firstFragment.getSecondFragmentContainer() == R.id.one_frame
                && fm.findFragmentById(
                        R.id.one_frame) instanceof com.lgallardo.qbittorrentclient.ItemstFragment) {

            com.lgallardo.qbittorrentclient.ItemstFragment fragment = (com.lgallardo.qbittorrentclient.ItemstFragment) fm
                    .findFragmentById(R.id.one_frame);

            if (fragment.getListView().getCount() == 0) {

                // Create the about fragment
                aboutFragment = new AboutFragment();

                fragmentTransaction.replace(R.id.one_frame, aboutFragment, "firstFragment");

                fragmentTransaction.commit();

                // Se title
                //                    setTitle(navigationDrawerItemTitles[drawerList.getCheckedItemPosition()]);
                //                    setTitle(navigationDrawerItemTitles[DrawerItemRecyclerViewAdapter.actionPosition]);
                setSelectionAndTitle(lastState);

                // Close Contextual Action Bar
                if (firstFragment != null && firstFragment.mActionMode != null) {
                    firstFragment.mActionMode.finish();
                }

                // Refresh current list
                refreshCurrent();
            }

        }
        if (fm.getBackStackEntryCount() == 0 && firstFragment.getSecondFragmentContainer() == R.id.content_frame
                && (fm.findFragmentByTag("secondFragment") instanceof AboutFragment)) {

            // Create the about fragment
            aboutFragment = new AboutFragment();

            fragmentTransaction.replace(R.id.content_frame, aboutFragment, "secondFragment");

            fragmentTransaction.commit();

            // Se title
            //                setTitle(navigationDrawerItemTitles[drawerList.getCheckedItemPosition()]);
            //                setTitle(navigationDrawerItemTitles[DrawerItemRecyclerViewAdapter.actionPosition]);
            setSelectionAndTitle(lastState);

            // Close Contextual Action Bar
            if (firstFragment != null && firstFragment.mActionMode != null) {
                firstFragment.mActionMode.finish();
            }

            // Refresh current list
            refreshCurrent();

        }
    } catch (Exception e) {

    }
}