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: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 ww . ja v a  2 s.c o m
}

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();/* w ww.ja  v  a2  s .  c o  m*/
}

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();//  www  .ja  v a 2s  .  co m
}

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

public void addQuestionListFragment() {
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    QuestionListFragment cuQuestionFragment = new QuestionListFragment();
    fragmentTransaction.replace(R.id.fragment_container, cuQuestionFragment);
    fragmentTransaction.commit();/*from w  w w  . j  a va 2 s  . co m*/
}

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

public void addUserListFragment() {
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    AdminStatisticFragment cuQuestionFragment = new AdminStatisticFragment();
    fragmentTransaction.replace(R.id.fragment_container, cuQuestionFragment);
    fragmentTransaction.commit();//from  ww  w  . j  av a2  s .  co  m
}

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

public void addTestLicenseFragment() {
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    TestLicense testLicense = new TestLicense();
    testLicense.setUserModel(userModel);
    fragmentTransaction.replace(R.id.fragment_container, testLicense);
    fragmentTransaction.commit();//from  w ww  .j a  v  a 2s.c o m
}

From source file:it.unipr.informatica.autobusparma.MainActivity.java

/**
 * Diplaying fragment view for selected nav drawer list item
 * *///from w w  w  .  j av  a 2  s .  c  o  m
private void displayView(int position) {
    // update the main content by replacing fragments
    Fragment fragment = null;

    if (controllaPosizione(currentPosition, position))
        return;

    switch (position) {
    case 0:
        currentPosition = 0;
        fragment = new MappaFragment();
        break;
    case 1:
        currentPosition = 1;
        fragment = new CalcolaPercorso();
        break;
    case 2:
        currentPosition = 2;
        fragment = new OrariFragment();
        break;
    case 3:
        currentPosition = 3;
        fragment = new ProntobusFragment();
        break;
    case 4:
        currentPosition = 4;
        fragment = new TepFragment();
        break;
    case 5:
        currentPosition = 5;
        fragment = new InfoNotizie();
        break;
    case 6:
        currentPosition = 6;
        fragment = new OpzioniFragment();
        break;

    default:
        break;
    }

    if (fragment != null) {
        FragmentManager fragmentManager = getFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.frame_container, fragment).commit();

        // update selected item and title, then close the drawer
        mDrawerList.setItemChecked(position, true);
        mDrawerList.setSelection(position);
        setTitle(navMenuTitles[position]);
        mDrawerLayout.closeDrawer(mDrawerList);
    } else {
        // error in creating fragment
        Log.e("MainActivity", "Error in creating fragment");
    }
}

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

public void addStatisticFragment() {

    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    StatisticFragment statisticFragment = new StatisticFragment();
    statisticFragment.setUserModel(userModel);
    fragmentTransaction.replace(R.id.fragment_container, statisticFragment);
    fragmentTransaction.commit();//from   w  w  w  .java 2 s.c o  m

}

From source file:com.mobile.syslogng.monitor.MainActivity.java

public void setFragment(Fragment fragment, Integer position, String tag) {

    updateDrawer(position);/*from   w  ww  . j  a v a 2s  . c  o  m*/
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction transaction = fragmentManager.beginTransaction();
    Bundle args = new Bundle();
    args.putInt(MainActivity.FRAGMENT_POS, position);
    fragment.setArguments(args);
    String cTag = "empty";
    Fragment currentFragment = fragmentManager.findFragmentById(R.id.container);
    if (currentFragment != null) {
        cTag = currentFragment.getTag();
        if (!cTag.equals(tag)) {
            if (currentFragment instanceof WelcomeFragment
                    || currentFragment instanceof MonitoredSyslogngFragment
                    || currentFragment instanceof AboutFragment) {
                stackCount = 0;
                transaction.addToBackStack(cTag);
                stackCount++;
            } else {
                if (stackCount < 2) {
                    transaction.addToBackStack(cTag);
                    stackCount++;
                }
            }
        }
    }
    transaction.replace(R.id.container, fragment, tag).commit();
}

From source file:com.bulletingroupblast.bulletingroupblast.GroupActivity.java

@Override
public void onNavigationDrawerItemSelected(int position) {
    // update the main content by replacing fragments
    Fragment fragment = null;//from w ww. jav  a 2 s  .  co m
    Bundle args = new Bundle(); // For passing arguments

    // This is the click event switch for each menu item
    switch (position) {
    case 0:
        // Overview Fragment
        fragment = new GroupOverviewFragment();
        break;
    case 1:
        // News list fragment
        fragment = new NewsItemFragment();
        break;
    case 2:
        // Events list fragment
        fragment = new EventItemFragment();
        break;
    case 3:
        // Chat fragment
        fragment = new ChatFragment();
        break;
    case 4:
        // Users fragment
        fragment = new UserItemFragment();
        break;
    default:
        // open the overview for default
        fragment = new GroupOverviewFragment();
        break;
    }

    // Check if fragment is valid
    if (fragment == null) {
        Log.e("GroupActivity", "Error in creating fragment");
    }

    // Pass organization id and name
    args.putInt(GRP_ID, groupId);
    if (mGroup != null) {
        args.putString(GRP_NAME, mGroup.getName());
    }

    // update the main content by replacing fragments
    FragmentManager fragmentManager = this.getFragmentManager();

    // Replace the fragment with selected fragment
    fragmentManager.beginTransaction().replace(R.id.container, fragment).commit();
}