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.richtodd.android.quiltdesign.app.BrowserActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_browser);
    getActionBar().setDisplayHomeAsUpEnabled(true);

    m_urlArgument = getIntent().getStringExtra(ARG_URL);

    FragmentManager fm = getFragmentManager();

    // Create color settings fragment.
    {//from  w  w  w.j ava 2s.  co  m
        Fragment f = fm.findFragmentById(R.id.layout_container);
        if (f == null) {
            f = BrowserFragment.create(m_urlArgument);
            fm.beginTransaction().add(R.id.layout_container, f).commit();
        }
    }
}

From source file:org.mars3142.android.toaster.activity.MainActivity.java

@Override
public void onNavigationDrawerItemSelected(String packageFilter) {
    FragmentManager fragmentManager = getFragmentManager();
    Fragment fragmentView = ToasterFragment.newInstance(packageFilter);
    fragmentManager.beginTransaction().replace(R.id.container, fragmentView).commit();
}

From source file:com.android.navigationdrawer.MainActivity.java

private void insertFragment(Fragment fragment, Bundle args) {
    fragment.setArguments(args);//w w w .  ja  v  a  2s  . co m
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction transaction = fragmentManager.beginTransaction();
    transaction.replace(R.id.content_frame, fragment).commit();
}

From source file:cn.androidy.swiftlib.navigationdrawer.NavigationDrawerActivity.java

private void selectItem(int position) {
    // update the main content by replacing fragments
    Fragment fragment = PlanetFragment.newInstance(position);

    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction ft = fragmentManager.beginTransaction();
    ft.replace(R.id.content_frame, fragment);
    ft.commit();//from   w  w w  .ja  v a2 s.  com

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

From source file:pace.cs389.team2.quickfitness.MainActivity.java

public void selectItem(int position) {

    Fragment fragment = null;//from  w ww  .ja  v  a  2 s  . c om
    Bundle args = new Bundle();
    switch (position) {

    case 0:
        fragment = new FragmentOne();
        args.putString(FragmentOne.ITEM_NAME, mDataList.get(position).getmNameItem());
        args.putInt(FragmentOne.IMAGE_RESOURCE_ID, mDataList.get(position).getmIconRes());
        break;
    case 1:
        fragment = new FragmentOne();
        args.putString(FragmentOne.ITEM_NAME, mDataList.get(position).getmNameItem());
        args.putInt(FragmentOne.IMAGE_RESOURCE_ID, mDataList.get(position).getmIconRes());
        break;
    case 2:
        fragment = new FragmentOne();
        args.putString(FragmentOne.ITEM_NAME, mDataList.get(position).getmNameItem());
        args.putInt(FragmentOne.IMAGE_RESOURCE_ID, mDataList.get(position).getmIconRes());
        break;
    case 3:
        fragment = new FragmentOne();
        args.putString(FragmentOne.ITEM_NAME, mDataList.get(position).getmNameItem());
        args.putInt(FragmentOne.IMAGE_RESOURCE_ID, mDataList.get(position).getmIconRes());
        break;
    case 4:
        fragment = new FragmentOne();
        args.putString(FragmentOne.ITEM_NAME, mDataList.get(position).getmNameItem());
        args.putInt(FragmentOne.IMAGE_RESOURCE_ID, mDataList.get(position).getmIconRes());
        break;
    case 5:
        fragment = new FragmentOne();
        args.putString(FragmentOne.ITEM_NAME, mDataList.get(position).getmNameItem());
        args.putInt(FragmentOne.IMAGE_RESOURCE_ID, mDataList.get(position).getmIconRes());
        break;
    case 6:
        fragment = new FragmentOne();
        args.putString(FragmentOne.ITEM_NAME, mDataList.get(position).getmNameItem());
        args.putInt(FragmentOne.IMAGE_RESOURCE_ID, mDataList.get(position).getmIconRes());
        break;
    default:
        break;
    }

    fragment.setArguments(args);
    FragmentManager frgManager = getFragmentManager();
    frgManager.beginTransaction().replace(R.id.content_place_holder, fragment).commit();

    mDrawerList.setItemChecked(position, true);
    setTitle(mDataList.get(position).getmNameItem());
    mDrawerLayout.closeDrawer(mDrawerList);

}

From source file:br.edu.ufabc.padm.cardioufabc.MainActivity.java

private void selectItem(int position) {
    Fragment fragment = null;//from w  w  w .  j  a v a  2  s. c om

    String menuItem = menuItems[position];

    switch (menuItem) {
    case "Home":
        fragment = new HomeFragment();
        break;
    case "Medidor":
        fragment = new CriarAtividadeFragment();
        break;
    case "Estatstica":
        fragment = new EstatisticaFragment();
        break;
    case "Calendrio":
        fragment = new CalendarioFragment();
        break;
    case "Atividades":
        fragment = new AtividadesFragment();
        break;
    case "Configuraes":
        fragment = new ConfiguracaoFragment();
        break;
    }

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

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

From source file:am.project.x.business.main.MainActivity.java

private void setFragment(String tag) {
    final String oldTag = mCurrent;
    mCurrent = tag;// www  . j a va2s . c o  m
    final FragmentManager manager = getFragmentManager();
    final FragmentTransaction transaction = manager.beginTransaction();
    if (!TextUtils.isEmpty(oldTag)) {
        final Fragment old = manager.findFragmentByTag(oldTag);
        if (old != null && old.isVisible()) {
            transaction.hide(old);
        }
    }
    Fragment target = manager.findFragmentByTag(tag);
    if (target != null && target.isVisible())
        return;
    if (target == null) {
        switch (tag) {
        default:
        case TAG_WIDGETS:
            target = WidgetsFragment.newInstance();
            break;
        case TAG_DRAWABLES:
            target = DrawablesFragment.newInstance();
            break;
        case TAG_OTHERS:
            target = OthersFragment.newInstance();
            break;
        case TAG_DEVELOP:
            target = DevelopFragment.newInstance();
            break;
        }
        transaction.add(mVContent.getId(), target, tag);
    }
    transaction.show(target);
    transaction.commit();
}

From source file:com.Candy.ota.CandyOTA.java

private void addShortCutFragment() {
    FragmentManager fragmentManager = this.getActivity().getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    CandyLinks candyLinks = new CandyLinks();
    fragmentTransaction.replace(R.id.linksFragment, candyLinks);
    fragmentTransaction.commit();//from www .  j av a 2 s.  c  o m
}

From source file:com.global.fragment.NativeMenuFragment.java

private void selectItem(int position) {
    // update the main content by replacing fragments
    Fragment fragment = new CheckSimFragment();
    Bundle args = new Bundle();
    args.putInt(PlanetFragment.ARG_PLANET_NUMBER, position);
    fragment.setArguments(args);//from   w w w  .  j ava2 s .  c  om

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

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

From source file:edu.nau.CS477.Classes.MainActivity.java

private void selectItem(int position) {
    Bundle args = new Bundle();

    Fragment fragment = null;// www.ja v a 2s  .c  o m
    switch (position) {
    case 0:
        fragment = new ContactsFragment();
        args.putInt(ContactsFragment.MENU_ITEM_NUMBER, position);
        fragment.setArguments(args);
        break;
    case 1:
        fragment = new ChatFragment();
        args.putInt(ChatFragment.MENU_ITEM_NUMBER, position);
        fragment.setArguments(args);
        break;
    case 2:
        fragment = new FileBrowserFragment();
        args.putInt(FileBrowserFragment.MENU_ITEM_NUMBER, position);
        fragment.setArguments(args);
        break;
    case 3:
        fragment = new FTPTransferFragment();
        args.putInt(FTPTransferFragment.MENU_ITEM_NUMBER, position);
        fragment.setArguments(args);
        break;
    case 4:
        fragment = new SettingsFragment();
        args.putInt(SettingsFragment.MENU_ITEM_NUMBER, position);
        fragment.setArguments(args);
        break;

    default:
        break;
    }

    if (fragment != null) {

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

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

}