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:me.isassist.isa.MainActivity.java

public void showLoadingFragment(String text) {
    //show the main fragment with instruction picture
    Bundle args = new Bundle();
    args.putString("LOADING_TEXT", text);
    Fragment loadingFragment = new LoadingFragment();
    loadingFragment.setArguments(args);//w w w  .  j a  v a2s .c o  m
    FragmentManager fragmentManager = getFragmentManager();
    fragmentManager.beginTransaction().replace(R.id.fragment_container, loadingFragment).commit();

}

From source file:me.isassist.isa.MainActivity.java

public void showMainFragment() {
    //show the main fragment with instruction picture
    Fragment mainFragment = new MainFragment();
    FragmentManager fragmentManager = getFragmentManager();
    fragmentManager.beginTransaction().replace(R.id.fragment_container, mainFragment).commit();

    // nie rusza - nie wiem czemu ale sprawia problemy
    final LocationManager manager = (LocationManager) getSystemService(this.LOCATION_SERVICE);
    if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        buildAlertMessageNoGps();/*from   ww  w  . ja v  a2s .  c  om*/
    }

}

From source file:com.android.calendar.SearchActivity.java

private void initFragments(long timeMillis, String query) {
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction ft = fragmentManager.beginTransaction();

    AgendaFragment searchResultsFragment = new AgendaFragment(timeMillis, true);
    ft.replace(R.id.search_results, searchResultsFragment);
    mController.registerEventHandler(R.id.search_results, searchResultsFragment);

    ft.commit();//from   w w w.  j  av a2  s.  com
    Time t = new Time();
    t.set(timeMillis);
    search(query, t);
}

From source file:com.android.calendar.SearchActivity.java

private void deleteEvent(long eventId, long startMillis, long endMillis) {
    mDeleteEventHelper.delete(startMillis, endMillis, eventId, -1);
    if (mIsMultipane && mEventInfoFragment != null && eventId == mCurrentEventId) {
        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction ft = fragmentManager.beginTransaction();
        ft.remove(mEventInfoFragment);/*w w  w .j  av a  2 s  . c  o m*/
        ft.commit();
        mEventInfoFragment = null;
        mCurrentEventId = -1;
    }
}

From source file:de.jadehs.jadehsnavigator.MainActivity.java

private void displayView(int position) {
    // show fragment
    Fragment fragment = null;//from  ww w.j  a  va 2s. co m
    String fragmentTag = "";
    switch (position) {
    case 0:
        fragment = new NewsFragment();
        fragmentTag = navMenuTitles[1];
        break;
    case 1:
        fragment = new InfoSysFragment();
        fragmentTag = navMenuTitles[2];
        break;
    case 2:
        fragment = new VorlesungsplanFragment();
        fragmentTag = navMenuTitles[3];
        break;
    case 3:
        fragment = new MensaplanFragment();
        fragmentTag = navMenuTitles[4];
        break;
    case 4:
        fragment = new MapFragment();
        fragmentTag = navMenuTitles[5];
        break;
    case 5:
        fragment = new AboutFragment();
        fragmentTag = navMenuTitles[6];
        break;
    case 6:
        Intent intent = new Intent(MainActivity.this, SettingsActivity.class);
        startActivity(intent);
        break;
    default:
        break;
    }
    if (fragment != null) {
        FragmentManager fragmentManager = getFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.frame_container, fragment, fragmentTag)
                .addToBackStack(fragment.getTag()).commit();
        mDrawerLayout.closeDrawer(mDrawerList);
        mDrawerList.setItemChecked(position, true);
        mDrawerList.setSelection(position);
        setTitle(navMenuTitles[position]);
    } else {
        Log.e(TAG, "Error while creating fragment");
    }
}

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();//w  ww  . jav a  2 s . co m
        if (baseFragment.getTitleResourceId() > 0)
            mCurrentTitle = baseFragment.getTitleResourceId();
    }
}

From source file:com.sawyer.advadapters.app.adapters.jsonadapter.JSONAdapterActivity.java

@Override
protected void initFrags() {
    super.initFrags();
    FragmentManager manager = getFragmentManager();
    mListFragment = (JSONAdapterFragment) manager.findFragmentByTag(TAG_ADAPTER_FRAG);
    if (mListFragment == null) {
        mListFragment = JSONAdapterFragment.newInstance();
        FragmentTransaction transaction = manager.beginTransaction();
        transaction.replace(R.id.frag_container, mListFragment, TAG_ADAPTER_FRAG);
        transaction.commit();/* w w w.j  a  v a 2s.c o  m*/
    }

    mAddDialogFragment = (AddJSONArrayDialogFragment) manager.findFragmentByTag(TAG_ADD_DIALOG_FRAG);
    if (mAddDialogFragment != null) {
        mAddDialogFragment.setEventListener(this);
    }
}

From source file:com.emman.tame.MainActivity.java

public void onSectionAttached(int number) {
    Fragment fragment = null;/*  w w w.j a  v a 2  s.c  om*/
    switch (number) {
    case 1:
        mTitle = getString(R.string.page_main);
        fragment = new AboutTame();
        break;
    case 2:
        mTitle = getString(R.string.page_kernelsettings);
        fragment = new KernelSettings();
        break;

    case 3:
        mTitle = getString(R.string.page_cpusettings);
        fragment = new CPUSettings();
        break;

    case 4:
        mTitle = getString(R.string.page_generalsettings);
        fragment = new GeneralSettings();
        break;
    }
    if (fragment != null) {
        FragmentManager fragmentManager = getFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.container, fragment).commit();
        MainActivity.setOnBackPressedListener(null); //normal operations
    }
}

From source file:jsoft.projects.photoclick.Dashboard.java

/** Swaps fragments in the main content view */
private void selectItem(int position) {

    Fragment fragment = null;//from w w  w  .j  a  v  a 2 s  .  c o  m

    switch (position) {
    case 0: // MyGallery
        fragment = new MyGalleryFragment(selection);
        break;
    case 1: // Facebook
        Intent i = new Intent(this, FbGallery.class);
        startActivity(i);
        break;
    case 2: // User
        Intent i1 = new Intent(this, LoginActivity.class);
        startActivity(i1);
        break;
    //          case 3:      // Order History
    //             if(!cm.isOnline()){
    //                Toast toast = Toast.makeText(getApplicationContext(), "Not connected to network", Toast.LENGTH_LONG);
    //                toast.setGravity(Gravity.TOP, 0, 150);
    //                toast.show();
    //                return;
    //             }
    //             showOrderHistory();
    //             break;
    case 3: // Cart
        showCart();
        break;
    //            case 3:      // Cart
    //                Intent i2 = new Intent(this, LoginActivity.class);
    //                startActivity(i2);
    //                break;
    case 4: // Logout
        //             logout();
        break;
    default:
        break;
    }

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

        mDrawerList.setItemChecked(position, true);
        mDrawerList.setSelection(position);
        setTitle(navList[position]);
        mDrawerLayout.closeDrawer(mDrawerList);
    }

    //       Toast.makeText(getApplicationContext(), Integer.toString(position), Toast.LENGTH_LONG).show();

}

From source file:com.HACK.codersbestfriend.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // The action bar home/up action should open or close the drawer.
    // ActionBarDrawerToggle will take care of this.
    if (mDrawerToggle.onOptionsItemSelected(item)) {
        return true;
    }/* w  w w. j a va 2  s . co  m*/
    // Handle action buttons
    switch (item.getItemId()) {
    case R.id.timer:
        if (timerRunning)
            mCurrentFragment = new CodersBestFragment(R.layout.fragment_timer_stop);
        else
            mCurrentFragment = new CodersBestFragment(R.layout.fragment_timer);

        FragmentManager fragmentManager = getFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.content_frame, mCurrentFragment).commit();

        // update selected item and title, then close the drawer
        mDrawerList.setItemChecked(2, true);
        mDrawerLayout.closeDrawer(mDrawerList);
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}