Example usage for android.app FragmentTransaction commit

List of usage examples for android.app FragmentTransaction commit

Introduction

In this page you can find the example usage for android.app FragmentTransaction commit.

Prototype

public abstract int commit();

Source Link

Document

Schedules a commit of this transaction.

Usage

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  ww  .j  a v  a 2 s.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.hyung.jin.seo.getup.wear.G3tUpActivity.java

private void selectFragment() {
    fragment = null;//  w ww. ja v  a  2s  .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:org.dolphinemu.dolphinemu.gamelist.GameListActivity.java

/**
 * Switches to the {@link Fragment} represented
 * by the given ID number./* w w w .j a  v a2s .c  o m*/
 * 
 * @param toPage the number representing the {@link Fragment} to switch to.
 */
public void SwitchPage(int toPage) {
    if (mCurFragmentNum == toPage)
        return;

    switch (toPage) {
    case 0: // Game list
    {
        // We use the title section as the browser directory tracker in the folder browser.
        // Make sure we flip the title back if we're coming from that fragment.
        if (mCurFragmentNum == 1)
            setTitle(R.string.app_name);

        mCurFragmentNum = 0;
        final GameListFragment gameList = new GameListFragment();
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.replace(R.id.content_frame, gameList);
        ft.commit();
        invalidateOptionsMenu();
    }
        break;

    case 1: // Folder Browser
    {
        mCurFragmentNum = 1;
        final FolderBrowser folderBrowser = new FolderBrowser();
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.replace(R.id.content_frame, folderBrowser);
        ft.addToBackStack(null);
        ft.commit();
        invalidateOptionsMenu();
    }
        break;

    case 2: // Settings
    {
        Intent intent = new Intent(this, PrefsActivity.class);
        startActivity(intent);
    }
        break;

    case 3: // About
    {
        Intent intent = new Intent(this, AboutActivity.class);
        startActivity(intent);
    }
        break;

    default:
        break;
    }
}

From source file:edu.scranton.fisherc5.busybusy.MainActivity.java

public void setDailyViewFragment(Bundle args) {
    Fragment dailyViewFrag = new DailyViewFragment();
    dailyViewFrag.setArguments(args);// ww w .  ja v  a2  s .  co m
    SimpleDateFormat format = new SimpleDateFormat("MMMM d, yyyy");
    Calendar temp = new GregorianCalendar();
    temp.setTimeInMillis(args.getLong(Keys.SELECTED_DATE_KEY));

    getActionBar().setTitle(format.format(temp.getTime()));
    mDateInActionBar = true;

    //SET TRANSACTION.  ADD TO BACK STACK
    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.replace(R.id.content_frame, dailyViewFrag, "PRE_COMPARE");
    transaction.addToBackStack("PRE_COMPARE_PUSH");
    transaction.commit();
}

From source file:android.support.v13.app.FragmentTabHost.java

public void addTab(TabHost.TabSpec tabSpec, Class<?> clss, Bundle args) {
    tabSpec.setContent(new DummyTabFactory(mContext));
    String tag = tabSpec.getTag();

    TabInfo info = new TabInfo(tag, clss, args);

    if (mAttached) {
        // If we are already attached to the window, then check to make
        // sure this tab's fragment is inactive if it exists.  This shouldn't
        // normally happen.
        info.fragment = mFragmentManager.findFragmentByTag(tag);
        if (info.fragment != null && !info.fragment.isDetached()) {
            FragmentTransaction ft = mFragmentManager.beginTransaction();
            ft.detach(info.fragment);//from  ww  w . j  a  va 2  s .co  m
            ft.commit();
        }
    }

    mTabs.add(info);
    addTab(tabSpec);
}

From source file:de.azapps.mirakel.new_ui.activities.MirakelActivity.java

private void setList(final ListMirakel listMirakel) {
    final FragmentManager fragmentManager = getFragmentManager();
    final FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    final TasksFragment tasksFragment = getTasksFragment();
    tasksFragment.setList(listMirakel);/*from  ww  w.  j a  v  a 2 s  .  co  m*/
    fragmentTransaction.commit();
}

From source file:com.bct.gpstracker.util.FragmentTabHost.java

public void addTab(TabSpec tabSpec, Class<?> clss, Bundle args) {
    tabSpec.setContent(new DummyTabFactory(mContext));
    String tag = tabSpec.getTag();

    TabInfo info = new TabInfo(tag, clss, args);

    if (mAttached) {
        // If we are already attached to the window, then check to make
        // sure this tab's fragment is inactive if it exists.  This shouldn't
        // normally happen.
        info.fragment = mFragmentManager.findFragmentByTag(tag);
        if (info.fragment != null && !info.fragment.isDetached()) {
            FragmentTransaction ft = mFragmentManager.beginTransaction();
            ft.detach(info.fragment);/*from  w w w  .j a  va  2 s. co m*/
            ft.commit();
        }
    }

    mTabs.add(info);
    addTab(tabSpec);
}

From source file:com.ariesmcrae.eskwela.celebtweet.MainActivity.java

/** Add FeedFragment to Activity */
private FeedFragment addFeedFragment() {
    FeedFragment feedFragment;//w  w  w .  jav a  2  s . c o m
    feedFragment = new FeedFragment();

    FragmentTransaction transaction = mFragmentManager.beginTransaction();

    transaction.replace(R.id.fragment_container, feedFragment);
    transaction.addToBackStack(null);

    transaction.commit();
    mFragmentManager.executePendingTransactions();
    return feedFragment;
}

From source file:com.example.android.cloudnotes.ui.HomeActivity.java

/**
 * Callback from child fragment//from ww w  .  ja  v a  2  s .c o m
 */
public void onNoteDeleted() {
    // remove the NoteEditFragment after a deletion
    FragmentManager fm = getFragmentManager();
    NoteEditFragment edit = (NoteEditFragment) fm.findFragmentByTag(NOTE_EDIT_TAG);
    if (edit != null) {
        FragmentTransaction ft = fm.beginTransaction();
        ft.remove(edit);
        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
        ft.commit();
    }
}

From source file:ngoc.com.pedometer.ui.Activity_Main.java

@Override
protected void onCreate(final Bundle b) {
    super.onCreate(b);
    startService(new Intent(this, SensorListener.class));
    if (b == null) {
        // Create new fragment and transaction
        Fragment newFragment = new Fragment_Overview();
        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 w  w . j a  va2  s  .  com*/
}