Example usage for android.app FragmentTransaction add

List of usage examples for android.app FragmentTransaction add

Introduction

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

Prototype

public abstract FragmentTransaction add(@IdRes int containerViewId, Fragment fragment);

Source Link

Document

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

Usage

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

public void addLoginFragment() {
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    LoginFragment loginFragment = new LoginFragment();
    fragmentTransaction.add(R.id.fragment_container, loginFragment);
    fragmentTransaction.commit();/*from  ww  w  .  java  2 s  .  com*/
}

From source file:com.example.ogadrive.HomeActivity2.java

private void selectItem(int position) {
    // update the main content by replacing fragments
    Fragment fragment = null;/*from   ww  w. j  av  a2  s  .c om*/

    if (position == 1) {
        /*fragment = new HomeFragement();
        fragment.setArguments(bundle);*/

        fragment = new FragmentHistory();
        fragment.setArguments(bundle);
    } else if (position == 0) {
        fragment = new FragmentProfile();
        fragment.setArguments(bundle);

    } else if (position == 2) {

        setTitle("Contact Us");
    } else if (position == 3) {

        fragment = new FragmentHistory();
        fragment.setArguments(bundle);
    }

    if (fragment == null) {
        fragment = new HomeFragement();
        fragment.setArguments(bundle);
    }

    FragmentManager fragmentManager = getFragmentManager();
    // fragmentManager.popBackStack();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

    fragmentTransaction.add(R.id.content_frame, fragment);
    fragmentTransaction.addToBackStack(null);
    fragmentTransaction.commit();
    // fragmentTransaction.addToBackStack("hradesh").commit();
    // fragmentManager.getBackStackEntryAt(fragmentManager.getBackStackEntryCount()-1);

    // update selected item and title, then close the drawer
    mDrawerList.setItemChecked(position, true);

    // }
    mDrawerLayout.closeDrawer(mDrawerList);
}

From source file:com.optimusinfo.elasticpath.cortex.common.EPFragmentActivity.java

protected void addFragment(String title, int fargmentContainerId, EPFragment objFragment) {
    mStackLevel++;/*w w  w. j av a  2 s  .  co  m*/
    // Add the fragment to the activity, pushing this transaction
    // on to the back stack.
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    ft.setBreadCrumbTitle(title);
    ft.add(fargmentContainerId, objFragment);
    ft.commit();
}

From source file:org.worshipsongs.activity.CustomYoutubeBoxActivity.java

private void setYouTubePlayerFragment() {
    YouTubePlayerFragment youTubePlayerFragment = YouTubePlayerFragment.newInstance();
    youTubePlayerFragment.initialize("AIzaSyB7hLcRMs5KPZwElJnHBPK5DNmDqFxVy3s", this);
    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    if (isLandScape()) {
        transaction.remove(youTubePlayerFragment).commit();
    } else {//from  w w  w .java  2s.  com
        transaction.add(R.id.youtube_fragment, youTubePlayerFragment).commit();
    }
}

From source file:com.roodie.materialmovies.views.activities.SettingsActivity.java

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

    MMoviesApp.from(this).inject(this);

    setupActionBar();//w w w  . j av  a2 s .  c  o  m
    if (getDisplay() != null) {
        getDisplay().showUpNavigation(true);
        getDisplay().setActionBarTitle(MMoviesApp.get().getStringFetcher().getString(R.string.settings_title));
    }

    if (savedInstanceState == null) {
        Fragment fragment = new SettingsHeadersFragment();
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.add(R.id.content_frame, fragment);
        ft.commit();
    }
}

From source file:net.wespot.pim.controller.InquiryActivity.java

public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    if (savedInstanceState != null) {
        INQ.init(this);
        INQ.accounts.syncMyAccountDetails();
        INQ.inquiry.setCurrentInquiry(DaoConfiguration.getInstance().getInquiryLocalObjectDao()
                .load(savedInstanceState.getLong(CURRENT_INQUIRY)));

        INQ.inquiry.getCurrentInquiry().setRunLocalObject(DaoConfiguration.getInstance().getRunLocalObjectDao()
                .load(savedInstanceState.getLong(CURRENT_INQUIRY_RUN)));

        Log.e(TAG, "RUN ID: " + INQ.inquiry.getCurrentInquiry().getRunLocalObject().getId() + " "
                + INQ.inquiry.getCurrentInquiry().getRunLocalObject().getTitle());
        Log.e(TAG, "INQUIRY ID: " + INQ.inquiry.getCurrentInquiry().getId() + " "
                + INQ.inquiry.getCurrentInquiry().getTitle());
    }//from  w  ww . java2 s. c  o  m

    if (INQ.inquiry.getCurrentInquiry() == null) {
        Log.e(TAG, "New inquiry");

        setContentView(R.layout.wrapper);
        FragmentManager fragmentManager = getSupportFragmentManager();
        android.support.v4.app.FragmentTransaction fragmentTransaction;

        fragmentTransaction = fragmentManager.beginTransaction();
        InqCreateInquiryFragment fragment = new InqCreateInquiryFragment();
        fragmentTransaction.add(R.id.content, fragment);
        fragmentTransaction.commit();

        setTitle(R.string.actionbar_inquiry_list);

    } else {
        setContentView(R.layout.activity_inquiry);

        // Create an adapter that when requested, will return a fragment representing an object in
        // the collection.
        // ViewPager and its adapters use support library fragments, so we must use
        // getSupportFragmentManager.
        /*
          The {@link android.support.v4.view.PagerAdapter} that will provide fragments representing
          each object in a collection. We use a {@link android.support.v4.app.FragmentStatePagerAdapter}
          derivative, which will destroy and re-create fragments as needed, saving and restoring their
          state in the process. This is important to conserve memory and is a best practice when
          allowing navigation between objects in a potentially large collection.
         */
        InquiryPagerAdapter mInquiryPagerAdapter = new InquiryPagerAdapter(getSupportFragmentManager(),
                mViewPager);
        getmActionBarHelper().setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);

        // Set up the ViewPager, attaching the adapter.
        mViewPager = (ViewPager) findViewById(R.id.pager);
        mViewPager.setAdapter(mInquiryPagerAdapter);
        mViewPager.setOnPageChangeListener(this);

        // For each of the sections in the app, add a tab to the action bar.
        for (int i = 0; i < mInquiryPagerAdapter.getCount(); i++) {
            // Create a tab with text corresponding to the page title defined by the adapter.
            // Also specify this Activity object, which implements the TabListener interface, as the
            // listener for when this tab is selected.
            getmActionBarHelper().addTab(getmActionBarHelper().newTab()
                    .setText(mInquiryPagerAdapter.getPageTitle(i)).setTabListener(this));
        }

        getActionBar().setTitle(getResources().getString(R.string.actionbar_inquiry) + " - "
                + INQ.inquiry.getCurrentInquiry().getTitle());

        Bundle extras = getIntent().getExtras();
        if (extras != null) {
            mViewPager.setCurrentItem(extras.getInt(PHASE));
        }
    }
}

From source file:com.tozny.e3db.android.DefaultKeyAuthenticator.java

@RequiresApi(api = Build.VERSION_CODES.M)
@Override/*from   www .ja va2 s. c  o m*/
public void authenticateWithLockScreen(AuthenticateHandler cont) {
    DeviceCredentialsFragment f = new DeviceCredentialsFragment(cont, title,
            (KeyguardManager) activity.getSystemService(Context.KEYGUARD_SERVICE));
    FragmentManager fragmentManager = activity.getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.add(f, "device_credentials_fragment");
    fragmentTransaction.commit();
}

From source file:com.amazon.android.ui.widget.EllipsizedTextView.java

/**
 * Creates the read dialog fragment and adds it to the fragment.
 *///from  w w  w. ja v  a2s  .c om
private void showReadDialog() {
    // Show the dialog
    final ReadDialogFragment dialog = new ReadDialogFragment();
    if (mExpandedContentViewProvider == null) {
        dialog.setContentViewProvider(getDefaultExpandedContentProvider(this));
    } else {
        dialog.setContentViewProvider(mExpandedContentViewProvider);
    }

    if (mReadDialogHeight != 0 && mReadDialogWidth != 0) {
        final Bundle args = new Bundle();
        args.putInt(ReadDialogFragment.INTENT_EXTRA_DIALOG_WIDTH, mReadDialogWidth);
        args.putInt(ReadDialogFragment.INTENT_EXTRA_DIALOG_HEIGHT, mReadDialogHeight);

        dialog.setArguments(args);
    }

    // Commit allowing state loss, in case our activity is being destroyed we won't be in an
    // illegal state.
    final FragmentTransaction ft = ((Activity) getContext()).getFragmentManager().beginTransaction();
    ft.disallowAddToBackStack();
    ft.add(dialog, "read text");
    ft.commitAllowingStateLoss();
}

From source file:com.achep.acdisplay.acdisplay.AcDisplayActivity.java

/**
 * Initializes non-UI fragments such as {@link com.achep.acdisplay.fragments.PocketFragment}.
 *///  w  w w  . ja  v a 2  s  .  com
private void initInternalFragments() {
    FragmentTransaction ft = getFragmentManager().beginTransaction();

    // Turns screen off inside of your pocket.
    if (mConfig.isActiveModeEnabled()) {
        mPocketFragment = PocketFragment.newInstance();
        ft.add(mPocketFragment, PocketFragment.TAG);
    }

    ft.commit();
}

From source file:com.kriminal.main_activity.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);/*  w  ww  .  ja  va2s . c om*/

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);

    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG).setAction("Action", null)
                    .show();
        }
    });

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

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

    //Set fragments
    Class tasksView = TasksView.class;
    try {
        tasksList = (Fragment) tasksView.newInstance();
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
    //load list fragment
    Log.d(Utils.TAG, "before load fragment");
    if (savedInstanceState == null) {
        Log.d(Utils.TAG, "Going to load fragment");
        FragmentTransaction transaction = getFragmentManager().beginTransaction();
        //set animations
        transaction.setCustomAnimations(R.anim.enter, R.anim.exit, R.anim.pop_enter, R.anim.pop_exit);
        // transaction.addToBackStack(null);
        transaction.add(R.id.container, tasksList).commit();
    }

    // ATTENTION: This was auto-generated to implement the App Indexing API.
    // See https://g.co/AppIndexing/AndroidStudio for more information.
    client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
}