Example usage for android.app FragmentManager beginTransaction

List of usage examples for android.app FragmentManager beginTransaction

Introduction

In this page you can find the example usage for android.app FragmentManager beginTransaction.

Prototype

public abstract FragmentTransaction beginTransaction();

Source Link

Document

Start a series of edit operations on the Fragments associated with this FragmentManager.

Usage

From source file:com.casin.activity.HomeDrawerActivity.java

private void selectItem(int position, String tag) {

    String[] arrayAllData = { "Select Game", "Profile", "Change Password", "My Winnings", "Create User",
            "Transfer Points", "Settings", "Signout", "Create Broker" };
    Bundle args = new Bundle();

    // update the main content by replacing fragments
    Fragment fragment = new ProfileFragment();

    if (tag.equalsIgnoreCase(arrayAllData[0])) {
        fragment = new HomeFragment();
    } else if (tag.equalsIgnoreCase(arrayAllData[1])) {
        fragment = new ProfileFragment();

    } else if (tag.equalsIgnoreCase(arrayAllData[2])) {
        fragment = new ChangePasswordFragment();
    } else if (tag.equalsIgnoreCase(arrayAllData[3])) {
        fragment = new MyWinningsFragment();
    } else if (tag.equalsIgnoreCase(arrayAllData[4])) {
        args.putBoolean("isAdmin", false);
        fragment = new CreateUserFragment();
    } else if (tag.equalsIgnoreCase(arrayAllData[5])) {
        fragment = new TransferPointsFragment();
    } else if (tag.equalsIgnoreCase(arrayAllData[6])) {
        //settings
        fragment = new ProfileFragment();
    }//from   w  w w .jav a 2  s  . c  o  m

    else if (tag.equalsIgnoreCase(arrayAllData[7])) {
        //signout
        signOut(true, null);
    } else if (tag.equalsIgnoreCase(arrayAllData[8])) {
        fragment = new CreateUserFragment();
        args.putBoolean("isAdmin", true);
    }

    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:org.dolphinemu.dolphinemu.GameListActivity.java

public void SwitchPage(int toPage) {
    if (mCurFragmentNum == toPage)
        return;/*from w  w  w .j  a  v  a2 s. c om*/
    switch (mCurFragmentNum) {
    // Folder browser
    case 1:
        recreateFragment();
        break;
    // Settings
    case 2: {
        String Keys[] = { "cpupref", "dualcorepref", "gpupref", };
        String ConfigKeys[] = { "Core-CPUCore", "Core-CPUThread", "Core-GFXBackend", };

        keyTypes KeysTypes[] = { keyTypes.TYPE_STRING, keyTypes.TYPE_BOOL, keyTypes.TYPE_STRING, };
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());

        // Set our preferences here
        for (int a = 0; a < Keys.length; ++a) {
            String ConfigValues[] = ConfigKeys[a].split("-");
            String Key = ConfigValues[0];
            String Value = ConfigValues[1];

            switch (KeysTypes[a]) {
            case TYPE_STRING:
                String strPref = prefs.getString(Keys[a], "");
                NativeLibrary.SetConfig("Dolphin.ini", Key, Value, strPref);
                break;
            case TYPE_BOOL:
                boolean boolPref = prefs.getBoolean(Keys[a], true);
                NativeLibrary.SetConfig("Dolphin.ini", Key, Value, boolPref ? "True" : "False");
                break;
            }

        }
    }
        break;
    case 3: // Gamepad settings
    {
        InputConfigAdapter adapter = ((InputConfigFragment) mCurFragment).getAdapter();
        for (int a = 0; a < adapter.getCount(); ++a) {
            InputConfigItem o = adapter.getItem(a);
            String config = o.getConfig();
            String bind = o.getBind();
            String ConfigValues[] = config.split("-");
            String Key = ConfigValues[0];
            String Value = ConfigValues[1];
            NativeLibrary.SetConfig("Dolphin.ini", Key, Value, bind);
        }
    }
        break;
    case 0: // Game List
    case 4: // About
        /* Do Nothing */
        break;
    }
    switch (toPage) {
    case 0: {
        mCurFragmentNum = 0;
        mCurFragment = new GameListFragment();
        FragmentManager fragmentManager = getFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.content_frame, mCurFragment).commit();
    }
        break;
    case 1: {
        Toast.makeText(mMe, "Loading up the browser", Toast.LENGTH_SHORT).show();
        mCurFragmentNum = 1;
        mCurFragment = new FolderBrowser();
        FragmentManager fragmentManager = getFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.content_frame, mCurFragment).commit();
    }
        break;
    case 2: {
        Toast.makeText(mMe, "Loading up settings", Toast.LENGTH_SHORT).show();
        mCurFragmentNum = 2;
        mCurFragment = new PrefsFragment();
        FragmentManager fragmentManager = getFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.content_frame, mCurFragment).commit();
    }
        break;
    case 3: {
        Toast.makeText(mMe, "Loading up gamepad config", Toast.LENGTH_SHORT).show();
        mCurFragmentNum = 3;
        mCurFragment = new InputConfigFragment();
        FragmentManager fragmentManager = getFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.content_frame, mCurFragment).commit();
    }
        break;
    case 4: {
        Toast.makeText(mMe, "Loading up About", Toast.LENGTH_SHORT).show();
        mCurFragmentNum = 4;
        mCurFragment = new AboutFragment();
        FragmentManager fragmentManager = getFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.content_frame, mCurFragment).commit();
    }
        break;
    default:
        break;
    }
}

From source file:com.tobbetu.en4s.navigationDrawer.ListActivity.java

private void selectItem(int position) {
    // update the main content by replacing fragments
    Fragment fragment = new ComplaintListFragment();
    Bundle args = new Bundle();
    args.putInt(ComplaintListFragment.ARG_COMPLAINT_NUMBER, position);
    fragment.setArguments(args);/*w w w  .java2s.  c om*/

    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);
    setTitle(TITLES[position]);
    mDrawerLayout.closeDrawer(relativeDrawerLayout);
}

From source file:com.reallynourl.nourl.fmpfoldermusicplayer.ui.activity.MainActivity.java

private void loadFragmentToContent(IMainContent content) {
    FragmentManager fm = getFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    ft.replace(R.id.content_panel, content.getFragment(), CONTENT_FRAGMENT_TAG);
    ft.commit();/*from  w w  w.  j a  v  a  2 s.  c  o m*/
    SharedPreferences.Editor edit = PreferenceManager.getDefaultSharedPreferences(this).edit();
    edit.putString(getString(R.string.pref_last_main_content_fragment), content.getName());
    edit.apply();
    mActiveContent = content;
}

From source file:com.cloudbees.gasp.activity.PlacesDetailActivity.java

private void addGaspFragments() {
    FragmentManager fm = getFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();

    mGaspDatabaseFragment = new GaspDatabaseFragment();
    mGaspRestaurantFragment = new GaspRestaurantFragment() {
        @Override/*  ww  w  .j a v a 2s  .  com*/
        public void onSuccess(String location) {
            Log.d(TAG, "Gasp! restaurant added: " + location);
            mGaspRestaurantId = Integer.valueOf(location.substring(location.lastIndexOf("/") + 1));
            mGaspRestaurant = true;
            setButtons();
        }

        @Override
        public void onFailure() {
            Log.e(TAG, "Error adding Gasp! review");
        }
    };
    mGaspReviewFragment = new GaspReviewFragment() {
        @Override
        public void onSuccess(String location) {
            Log.d(TAG, "Gasp! review added: " + location);
        }

        @Override
        public void onFailure() {
            Log.e(TAG, "Error adding Gasp! review");
        }
    };

    ft.add(mGaspDatabaseFragment, getString(R.string.fragment_gasp_database));
    ft.add(mGaspRestaurantFragment, getString(R.string.fragment_gasp_restaurant));
    ft.add(mGaspReviewFragment, getString(R.string.fragment_gasp_review));

    ft.commit();
}

From source file:de.sourcestream.movieDB.controller.GenresList.java

/**
 * Callback method to be invoked when an item in this AdapterView has been clicked.
 *
 * @param parent   The AdapterView where the click happened.
 * @param view     The view within the AdapterView that was clicked (this will be a view provided by the adapter)
 * @param position The position of the view in the adapter.
 * @param id       The row id of the item that was clicked.
 *///from  www.j a  va 2s . c  o m
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    if (movieList.getCurrentList().equals("genre/" + genresList.get(position).getId() + "/movies"))
        movieList.setBackState(1);
    else {
        movieList.setCurrentList("genre/" + genresList.get(position).getId() + "/movies");
        movieList.setBackState(0);
    }
    movieList.setTitle(genresList.get(position).getName());
    FragmentManager manager = getFragmentManager();
    FragmentTransaction transaction = manager.beginTransaction();
    Bundle args = new Bundle();
    args.putString("currentList", "genresList");
    movieList.setArguments(args);
    transaction.replace(R.id.frame_container, movieList);
    // add the current transaction to the back stack:
    transaction.addToBackStack("genresList");
    transaction.commit();
    backState = 1;
}

From source file:com.hyung.jin.seo.getup.wear.G3tUpActivity.java

private void selectFragment() {
    fragment = null;//w  w  w.j  av a2 s . c  om
    // If CounterFragment is about to display, trigger timer as well
    if (status == G3tUpConstants.COUNTER_STATE) {
        fragment = new CounterFragment();
        CountDownTimer timer = new MyCountDownTimer(G3tUpConstants.SECOND * timerDuration * 60,
                G3tUpConstants.SECOND);
        timer.start();

        // ExerciseFragment
    } else if (status == G3tUpConstants.EXERCISE_STATE) {

        fragment = new ExerciseFragment();

        // DisplayFragment
    } else {

        fragment = new DisplayFragment();
    }
    FragmentManager fm = getFragmentManager();
    FragmentTransaction ftx = fm.beginTransaction();
    ftx.replace(R.id.fragment_place, fragment);
    ftx.commit();
}

From source file:com.ezhuk.cast.MainActivity.java

private void selectDrawerItem(int position) {
    FragmentManager fragmentManager = getFragmentManager();
    fragmentManager.beginTransaction()
            .replace(R.id.drawer_frame, (0 == position) ? new DevicesFragment() : new TextFragment()).commit();

    mDrawerList.setItemChecked(position, true);
    mDrawerLayout.closeDrawer(mDrawerList);
}

From source file:com.sage42.androidappaddicts.app.main.MainActivity.java

public void showFragment(final Fragment fragment, final boolean addToBackstack) {
    final FragmentManager fragmentManager = this.getFragmentManager();
    final FragmentTransaction transaction = fragmentManager.beginTransaction();
    transaction.replace(R.id.main_content_fragment, fragment);
    if (addToBackstack) {
        transaction.addToBackStack(null);

    } else {//from w  ww.ja  v  a2s.  c o  m
        this.clearAllBackStack();

        this.mDrawerToggle.syncState();
    }
    transaction.commit();

    // close the drawer
    this.mDrawerLayout.closeDrawer(this.mMenuDrawerList);
}

From source file:com.notriddle.budget.EnvelopesActivity.java

public void topFragment(Class<?> cls, int transition, Bundle args) {
    Fragment frag = Fragment.instantiate(this, cls.getName(), args);
    FragmentManager fragmentManager = getFragmentManager();
    fragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
    fragmentManager.beginTransaction().replace(R.id.content_frame, frag).setTransition(transition).commit();
    fragmentManager.executePendingTransactions();
    configureFragment(frag);/*from  w w w  .ja v a2 s. c o  m*/
}