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:org.horizonremote.MainActivity.java

private void showFragment(int type, int data) {
    Fragment fragment = null;/* ww w  .j a v  a2  s .c  o  m*/

    switch (type) {
    case FRAGMENT_MAIN:
        fragment = new MainFragment();
        break;
    case FRAGMENT_CONTROLLER:

        fragment = new ControllerFragment();
        Bundle args = new Bundle();

        ControllerInfo info = ControllerInfo.get(this, data);
        if (info != null) {

            setTitle(info.name);

            args.putInt(ControllerFragment.ARG_CONTROLLER_ID, data);
            fragment.setArguments(args);

            mDrawerLayout.closeDrawer(mDrawerContent);
        }
        break;
    }

    /* show fragment */

    if (fragment != null) {

        FragmentManager fragmentManager = getFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();

    }
}

From source file:com.pshelf.hugo.pshelf.PrincipalDrawer.java

private void selectItem(int position) {
    // update the main content by replacing fragments

    ProcessamentoFragment escolhadir = new ProcessamentoFragment();
    ClassificacaoFragment classific = new ClassificacaoFragment();

    Bundle args = new Bundle();
    FragmentManager fragmentManager = getFragmentManager();

    switch (position) {
    case 0:// w ww  .  jav  a 2  s  . c  o  m

        fragmentManager = getFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.content_frame, escolhadir).commit();

        break;

    case 1:

        fragmentManager = getFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.content_frame, classific).commit();

        break;

    }

    // update selected item and title, then close the drawer
    mDrawerList.setItemChecked(position, true);
    setTitle(mListaMenu[position]);
    mDrawerLayout.closeDrawer(mDrawerList);
}

From source file:org.noorganization.shoppinglist.view.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.

    FragmentManager fragMan = getFragmentManager();

    switch (item.getItemId()) {
    case R.id.action_create_list:
        fragMan.beginTransaction().add(new CreateListFragment(), null).commit();
        return true;
    case R.id.action_delete_list:
        fragMan.beginTransaction().add(new DeleteListFragment(), null).commit();
        return true;
    }/*from w w w.  j  a v  a 2s. c om*/

    return super.onOptionsItemSelected(item);
}

From source file:com.luorrak.ouroboros.thread.ThreadActivity.java

public void doPositiveClickInternal(String threadNo, String boardName) {
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

    //clear dialog fragments
    fragmentManager.popBackStack("threadDialog", FragmentManager.POP_BACK_STACK_INCLUSIVE);
    if (!threadNo.equals("0")) {
        threadDepth = threadDepth + 1;/* w ww .  j  a  v  a2s.  c  o  m*/
        threadFragment = new ThreadFragment().newInstance(threadNo, boardName);
        fragmentTransaction.replace(R.id.placeholder_card, threadFragment)
                .addToBackStack("threadDepth" + String.valueOf(threadDepth)).commit();
    } else {
        Intent intent = new Intent(this, CatalogActivity.class);
        intent.putExtra(Util.INTENT_BOARD_NAME, boardName);
        startActivity(intent);

    }

}

From source file:com.zprogrammer.tool.ui.MainActivity.java

@Override
public void onNavigationDrawerItemSelected(int position) {
    // update the main content by replacing fragments
    FragmentManager fragmentManager = getFragmentManager();
    /*        switch (position) {
    case 1:// w  w  w . ja v a2 s.  com
        CrashReport.testJavaCrash();
        return;
            }*/
    fragmentManager.beginTransaction().replace(R.id.container, fragments[position]).commit();
    onSectionAttached(position);
}

From source file:com.sharklee.navigationDrawer.MainActivity.java

private void selectItem(int position) {
    // update the main content by replacing fragments
    Fragment fragment = new PlanetFragment();
    Bundle args = new Bundle();
    args.putInt(PlanetFragment.ARG_PLANET_NUMBER, position);
    //??PlanetFragment?
    fragment.setArguments(args);/*w  w w . j  a  v a  2s  .c  o m*/
    //PlanetFragment?FrameLayout??
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.replace(R.id.content_frame, fragment);
    fragmentTransaction.addToBackStack("");
    fragmentTransaction.commit();

    // update selected item and title, then close the drawer
    //MainActivityposition=0?ListView?ListView?ListView?position=0
    mDrawerList.setItemChecked(position, true);
    setTitle(mPlanetTitles[position]);
    mDrawerLayout.closeDrawer(mDrawerList);
}

From source file:com.techsoc.cultureconnect.navigation.NavigationActivity.java

private void selectItem(int position) {

    // update the main content by replacing fragments
    int talkIntent = 0;

    Fragment fragment = null;//from  w  w w .ja va  2s. co m

    switch (position) {

    case 0:
        fragment = new FactsFragment();
        break;
    case 1:
        fragment = new PlacesFragment();
        break;
    case 2:
        break;
    case 3:
        break;
    case 4:
        break;
    case 5:
        talkIntent = 1;
        break;
    }

    if (talkIntent == 1) {

        Intent intent = new Intent(this, BluetoothChat.class);
        startActivity(intent);

    } else {

        FragmentManager fragmentManager = getFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();

        // update selected item and title, then close the drawer
        mDrawerListLeft.setItemChecked(position, true);
        setTitle(mOptions[position]);
        mDrawerLayout.closeDrawer(mDrawerListLeft);

    }

}

From source file:com.example.android.adrenaland.MainActivity.java

public void selectItem(int position) {
    // update the main content by replacing fragments
    Fragment fragment = new FragmentHome();
    switch (position) {
    case 0://  w w  w  .  j  av a  2s. co  m
        fragment = new FragmentHome();
        break;
    case 1:
        fragment = new FragmentNavigation();
        Bundle args = new Bundle();
        args.putBoolean(FragmentNavigation.ARG_CLOUD, false);
        args.putBoolean(FragmentNavigation.ARG_BIG_DROP, false);
        fragment.setArguments(args);
        break;
    case 2:
        fragment = new FragmentWaitTimes();
        break;
    case 3:
        fragment = new FragmentShowTimes();
        break;
    case 4:
        fragment = new FragmentRideInfo();
        break;
    case 5:
        fragment = new FragmentRollerCoasters();
        break;
    }
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction ft = fragmentManager.beginTransaction();
    ft.replace(R.id.content_frame, fragment).commit();

    // update selected item and title, then close the drawer
    if (position <= 4) {
        mDrawerList.setItemChecked(position, true);
    }
    mDrawerLayout.closeDrawer(mDrawerList);
}

From source file:fr.outadev.twistoast.MainActivity.java

@Override
public void loadFragmentFromDrawerPosition(int position) {
    currentFragmentIndex = position;/* w  w w. j  ava2 s .c  o  m*/

    if (frags[currentFragmentIndex] == null && drawerItems != null
            && drawerItems.size() > currentFragmentIndex) {
        try {
            frags[currentFragmentIndex] = drawerItems.get(currentFragmentIndex).getFragment();
        } catch (IllegalAccessException | InstantiationException e) {
            e.printStackTrace();
        }
    }

    // Insert the fragment by replacing any existing fragment
    FragmentManager fragmentManager = getFragmentManager();
    fragmentManager.beginTransaction().replace(R.id.content_frame, frags[currentFragmentIndex]).commit();

    // Highlight the selected item, update the title, and close the drawer
    checkDrawerItem(currentFragmentIndex);
    drawerLayout.closeDrawer(drawerList);
}

From source file:com.masil.android.navigationdrawer.NavigationDrawerActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // The action bar home/up action should open or close the drawer.
    // ActionBarDrawerToggle will take care of this.
    int id = item.getItemId();
    if (mDrawerToggle.onOptionsItemSelected(item)) {
        if (id == R.id.btn_home) {

            MasilFragment fragment = new MasilFragment();
            FragmentManager fragmentManager = getFragmentManager();
            FragmentTransaction ft = fragmentManager.beginTransaction();
            ft.replace(R.id.content_frame, fragment);
            ft.commit();//from  w ww  .j  a  v  a2  s.  c o  m
            return true;

        }

    }

    return super.onOptionsItemSelected(item);

}