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:android.support.v13.app.FragmentTabHost.java

@Override
public void onTabChanged(String tabId) {
    if (mAttached) {
        FragmentTransaction ft = doTabChanged(tabId, null);
        if (ft != null) {
            ft.commit();
        }/* www.  j  ava  2  s .c o  m*/
    }
    if (mOnTabChangeListener != null) {
        mOnTabChangeListener.onTabChanged(tabId);
    }
}

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

private void selectItem(int position) {
    // update the main content by replacing fragments
    Fragment fragment = new EndTripFragment();
    Bundle args = new Bundle();
    args.putInt(EndTripFragment.ARG_PLANET_NUMBER, position);
    fragment.setArguments(args);//from   w  ww .j a  va 2  s  .com

    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction ft = fragmentManager.beginTransaction();
    //ft.replace(R.id.content_frame, fragment);
    ft.add(R.id.content_frame, fragment);

    ft.addToBackStack("null");
    ft.commit();

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

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

public void donate() {
    try {//  w w  w  .jav  a2 s.c  o m
        getFragmentManager().beginTransaction().remove(p).commit();
    } catch (Exception e) {
        e.printStackTrace();
    }

    String[] s = new String[] { "Minimal Donation", "Medium Donation", "High Donation" };
    DonationsFragment donationsFragment = DonationsFragment.newInstance(BuildConfig.DEBUG, true, GOOGLE_PUBKEY,
            GOOGLE_CATALOG, s, false, null, null, null, false, null, null, false, null);
    android.support.v4.app.FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    transaction.replace(R.id.prefsfragment, donationsFragment);
    transaction.commit();
    assert (getSupportActionBar()) != null;
    getSupportActionBar().setTitle(R.string.donate);

}

From source file:com.example.atsuto5.yahoo_rss_reader.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mMainTopicsFragment = new MainTopicsFragment();

    android.app.FragmentManager fragmentManager = getFragmentManager();
    android.app.FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.add(R.id.fragment_container, mMainTopicsFragment);
    fragmentTransaction.commit();

    mToolbar = (Toolbar) findViewById(R.id.mainToolbar);
    mToolbar.setTitle("");
    mToolbar.setTitleMargin(140, 0, 0, 0);
    setSupportActionBar(mToolbar);//from  w  w  w  . j  ava  2  s . co m

    final DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);

    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, mToolbar,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close) {

        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);

            SharedPreferences data = getSharedPreferences("DataSave", Context.MODE_PRIVATE);
            String username = data.getString("USERNAME", "User Name");

            if (drawerFlag) {
                mUserNameTextView = (TextView) drawerView.findViewById(R.id.userName);
                mUserNameTextView.setText(username);
                drawerFlag = false;
            }
        }
    };
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

}

From source file:com.commonsware.android.pagercolumns.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);/*from w ww .ja v  a2  s.com*/

    ViewPager pager = (ViewPager) findViewById(R.id.pager);

    if (pager == null) {
        if (getFragmentManager().findFragmentById(R.id.editor1) == null) {
            SamplePagerAdapter adapter = buildAdapter();
            FragmentTransaction ft = getFragmentManager().beginTransaction();

            populateColumn(getFragmentManager(), ft, adapter, 0, R.id.editor1);
            populateColumn(getFragmentManager(), ft, adapter, 1, R.id.editor2);
            populateColumn(getFragmentManager(), ft, adapter, 2, R.id.editor3);
            ft.commit();
        }
    } else {
        SamplePagerAdapter adapter = buildAdapter();
        TabPageIndicator tabs = (TabPageIndicator) findViewById(R.id.titles);

        pager.setAdapter(adapter);
        tabs.setViewPager(pager);
    }
}

From source file:com.google.android.apps.forscience.whistlepunk.LicenseActivity.java

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

    setContentView(R.layout.activity_licenses);

    if (getFragmentManager().findFragmentByTag("list") == null) {
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.add(R.id.container, new LicenseListFragment(), "list");
        ft.commit();
    }/*from  w  ww.jav  a 2s  .c om*/

    final ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
}

From source file:de.mgd.simplesoundboard.MainActivity.java

private void initFragments() {
    FragmentTransaction tx = getFragmentManager().beginTransaction();

    if (soundResourceDao.hasCategories()) {
        tx.replace(R.id.content_nav, new SoundResourceCategoryFragment(), NAVIGATION_FRAGMENT_ID);
    }//from ww  w  . j  ava 2  s  . c  om
    tx.replace(R.id.content_root, new SoundResourceListFragment(), CONTENT_FRAGMENT_ID);
    tx.commit();
}

From source file:org.mariotaku.twidere.activity.support.BrowserActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    supportRequestWindowFeature(WindowCompat.FEATURE_ACTION_BAR);
    super.onCreate(savedInstanceState);
    final ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }/* w w  w .j av a 2s  . c om*/
    mUri = getIntent().getData();
    if (mUri == null) {
        Toast.makeText(this, R.string.error_occurred, Toast.LENGTH_SHORT).show();
        finish();
        return;
    }
    final FragmentTransaction ft = getFragmentManager().beginTransaction();
    final Fragment fragment = Fragment.instantiate(this, BaseWebViewFragment.class.getName());
    final Bundle bundle = new Bundle();
    bundle.putString(EXTRA_URI, mUri.toString());
    fragment.setArguments(bundle);
    ft.replace(android.R.id.content, fragment);
    ft.commit();
}

From source file:de.lebenshilfe_muenster.uk_gebaerden_muensterland.activities.MainActivity.java

private void setFragment(Fragment fragment, String actionBarTitle) {
    Log.d(TAG, "setFragment: " + actionBarTitle + StringUtils.SPACE + hashCode());
    final FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.replace(R.id.content_frame, fragment, actionBarTitle);
    transaction.addToBackStack(actionBarTitle);
    transaction.commit();
}

From source file:com.android.mail.browse.EmlViewerActivity.java

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

    final ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);

    final Intent intent = getIntent();
    final String action = intent.getAction();
    final String type = intent.getType();
    mAccountUri = intent.getParcelableExtra(EXTRA_ACCOUNT_URI);

    if (savedInstanceState == null) {
        if (Intent.ACTION_VIEW.equals(action) && MimeType.isEmlMimeType(type)) {
            final FragmentTransaction transaction = getFragmentManager().beginTransaction();
            transaction.add(R.id.eml_root, EmlMessageViewFragment.newInstance(intent.getData(), mAccountUri),
                    FRAGMENT_TAG);/*  ww  w  .j  a  v a2s  .c  o m*/
            transaction.commit();
        } else {
            LogUtils.wtf(LOG_TAG, "Entered EmlViewerActivity with wrong intent action or type: %s, %s", action,
                    type);
            finish(); // we should not be here. bail out. bail out.
            return;
        }
    } else {
        if (savedInstanceState.containsKey(SAVED_ACCOUNT)) {
            mAccount = savedInstanceState.getParcelable(SAVED_ACCOUNT);
        }
    }

    // Account uri will be null if we launched from outside of the app.
    // So just don't load an account at all.
    if (mAccountUri != null) {
        getLoaderManager().initLoader(ACCOUNT_LOADER, Bundle.EMPTY, mAccountLoadCallbacks);
    }
}