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);

Source Link

Document

Calls #replace(int,Fragment,String) with a null tag.

Usage

From source file:org.dolphinemu.dolphinemu.gamelist.GameListActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.gamelist_activity);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);

    // Construct list of items to add to the side menu.
    List<SideMenuItem> dir = new ArrayList<SideMenuItem>();
    dir.add(new SideMenuItem(getString(R.string.game_list), 0));
    dir.add(new SideMenuItem(getString(R.string.browse_folder), 1));
    dir.add(new SideMenuItem(getString(R.string.settings), 2));
    dir.add(new SideMenuItem(getString(R.string.about), 3));

    mDrawerAdapter = new SideMenuAdapter(this, R.layout.sidemenu, dir);
    mDrawerList.setAdapter(mDrawerAdapter);
    mDrawerList.setOnItemClickListener(mMenuItemClickListener);

    // Enable ActionBar app icon to behave as action to toggle nav drawer
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    // ActionBarDrawerToggle ties together the the proper interactions
    // between the sliding drawer and the action bar app icon
    mDrawerToggle = new ActionBarDrawerToggle(this, /* Host Activity */
            mDrawerLayout, /* DrawerLayout object */
            R.drawable.ic_drawer, /* Navigation drawer image to replace 'Up' caret */
            R.string.drawer_open, /* "open drawer" description for accessibility */
            R.string.drawer_close /* "close drawer" description for accessibility */
    ) {/*from w w w .  j  av a  2s  . c o m*/
        public void onDrawerClosed(View view) {
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }

        public void onDrawerOpened(View drawerView) {
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    // Stuff in this block only happens when this activity is newly created (i.e. not a rotation)
    if (savedInstanceState == null) {
        // Copy assets into appropriate locations.
        Intent copyAssets = new Intent(this, AssetCopyService.class);
        startService(copyAssets);

        // Display the game list fragment.
        final GameListFragment gameList = new GameListFragment();
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.replace(R.id.content_frame, gameList);
        ft.commit();
    }

    // Create an alert telling them that their phone sucks
    if (Build.CPU_ABI.contains("arm") && !NativeLibrary.SupportsNEON()) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(R.string.device_compat_warning);
        builder.setMessage(R.string.device_compat_warning_msg);
        builder.setPositiveButton(R.string.yes, null);
        builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        });
        builder.show();
    }
}

From source file:com.pedometrak.ui.ActivityMain.java

@Override
protected void onCreate(final Bundle b) {
    super.onCreate(b);

    if (b == null) {
        // Create new fragment and transaction
        Fragment newFragment = new FragmentOverviewController();
        FragmentTransaction transaction = getFragmentManager().beginTransaction();

        // Replace whatever is in the fragment_container view with this
        // fragment,
        // and add the transaction to the back stack
        transaction.replace(android.R.id.content, newFragment);

        // Commit the transaction
        transaction.commit();/* w  ww .j  ava2 s . c  o  m*/
    }

    Logger.log("Unsaved sessions: " + LocalDatabaseManager.getInstance(this).getUnsynchedSessions().size());
}

From source file:com.dono.psakkos.dono.MainActivity.java

private void showAddLabelFragment() {
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

    AddLabelFragment addlabelFragment = new AddLabelFragment();
    fragmentTransaction.replace(R.id.mainFragment, addlabelFragment);
    fragmentTransaction.commit();//ww  w  .  java 2  s  .c  o m
}

From source file:org.cirrus.mobi.pegel.ListRiverFragment.java

private void showDetails(int position) {

    getListView().setItemChecked(position, true);

    if (position != mCurCheckPosition) {
        //transit to new Fragment
        MeasurePointFragment mpf = MeasurePointFragment.newInstance(this.abstractSR.rivers[position]);

        android.support.v4.app.FragmentTransaction transaction = getActivity().getSupportFragmentManager()
                .beginTransaction();/*from  www . j  a  v  a  2  s .  c om*/

        // Replace whatever is in the fragment_container view with this fragment,
        // and add the transaction to the back stack
        transaction.replace(R.id.MeasurePoints, mpf);
        //transaction.addToBackStack(null);
        // Commit the transaction
        transaction.commit();

        mCurCheckPosition = position;
    }
}

From source file:com.galois.qrstream.MainActivity.java

private void showFragment(Fragment fragment, boolean addToBackStack) {
    FragmentTransaction ft = fragmentManager.beginTransaction();

    // Replace null parameter with string only if
    // change to ft.replace(int,Fragment,String)
    ft.replace(R.id.container, fragment);
    if (addToBackStack) {
        ft.addToBackStack(null);/*  www . ja  va2s .c  o m*/
    }
    ft.commit();
    lastFragment = currentFragment;
    currentFragment = fragment;
}

From source file:edu.jcu.cs470.togenda.MainActivity.java

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    //refresh the current fragment.
    FragmentTransaction tr = getFragmentManager().beginTransaction();
    if (gPosition == 0) {
        tr.replace(R.id.content_frame, new AgendaFragment());
    } else //if not in agenda view, go to todo view.
    {/*from  w  ww. j  ava 2s . c o m*/
        tr.replace(R.id.content_frame, new ToDoFragment());
    }
    tr.commit();

}

From source file:com.example.koppa.driverlicensev2.MainActivity.java

public void addPracticeFragment() {
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    PracticeFragment practiceFragment = new PracticeFragment();
    fragmentTransaction.replace(R.id.fragment_container, practiceFragment);
    fragmentTransaction.commit();//from w w  w  . j a v  a2s.  co m
}

From source file:it.gmariotti.cardslib.demo.extras.MainActivity.java

private void openFragment(BaseFragment baseFragment) {
    if (baseFragment != null) {
        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

        fragmentTransaction.replace(R.id.fragment_main_extras, baseFragment);
        //fragmentTransaction.addToBackStack(null);
        fragmentTransaction.commit();//from w ww.  ja  v a  2s. c om
        if (baseFragment.getTitleResourceId() > 0)
            mCurrentTitle = baseFragment.getTitleResourceId();
    }
}

From source file:com.amaze.filemanager.activities.Preferences.java

public void selectItem(int i) {
    switch (i) {//from w  w  w  .  j a  v a2 s.  c  o m
    case 0:
        p = new Preffrag();
        FragmentTransaction transaction = getFragmentManager().beginTransaction();
        transaction.replace(R.id.prefsfragment, p);
        transaction.commit();
        select = 0;
        getSupportActionBar().setTitle(R.string.setting);
        break;
    case 1:
        FragmentTransaction transaction1 = getFragmentManager().beginTransaction();
        transaction1.replace(R.id.prefsfragment, new ColorPref());
        transaction1.commit();
        select = 1;
        getSupportActionBar().setTitle(R.string.color_title);
        break;
    }
}

From source file:com.example.koppa.driverlicensev2.MainActivity.java

public void addCUQuestionFragment() {
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    AddQuestionFragment addQuestionFragment = new AddQuestionFragment();
    fragmentTransaction.replace(R.id.fragment_container, addQuestionFragment);
    fragmentTransaction.commit();//from  w w w  . j av  a2s .c o m
}