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.royclarkson.springagram.MainActivity.java

@Override
public void onGalleryPhotoSelected(int position) {
    PhotoDetailFragment photoDetailFragment = PhotoDetailFragment.newInstance(position);
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction transaction = fragmentManager.beginTransaction()
            .add(R.id.container, photoDetailFragment).addToBackStack(null);
    transaction.commit();/*from  ww w . j a  v a2  s .  com*/
}

From source file:com.zzolta.android.gfrecipes.activities.MainActivity.java

@Override
public void onNavigationDrawerItemSelected(int position, boolean fromSavedInstanceState) {
    if (!fromSavedInstanceState) {
        final FragmentManager fragmentManager = getFragmentManager();
        final Fragment fragment;
        switch (Section.values()[position]) {
        case RECIPE_OF_THE_DAY:
            fragment = setupRecipeDetailFragment(position);
            fragmentManager.beginTransaction().replace(R.id.container, fragment).commit();
            break;
        case SEARCH:
            startActivity(new Intent(getApplicationContext(), SearchResultsActivity.class));
            break;
        case MY_RECIPES:
            startActivity(new Intent(getApplicationContext(), MyRecipesActivity.class));
            break;
        case FEEDBACK:
            fragment = setupFeedbackFragment(position);
            fragmentManager.beginTransaction().replace(R.id.container, fragment).commit();
            break;
        default://from ww w.j  a  v a 2 s .c om
            break;
        }
    }
}

From source file:com.sawyer.advadapters.app.adapters.nfjsonadapter.NFJSONAdapterActivity.java

@Override
protected void initFrags() {
    super.initFrags();
    FragmentManager manager = getFragmentManager();
    mListFragment = (NFJSONAdapterFragment) manager.findFragmentByTag(TAG_ADAPTER_FRAG);
    if (mListFragment == null) {
        mListFragment = NFJSONAdapterFragment.newInstance();
        FragmentTransaction transaction = manager.beginTransaction();
        transaction.replace(R.id.frag_container, mListFragment, TAG_ADAPTER_FRAG);
        transaction.commit();/*from  w  ww. jav a 2  s. com*/
    }

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

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

public void newTaskSpawn(View view) {
    mCurrentFragment = new NewTaskFragment();
    Bundle args = new Bundle();
    args.putInt(ARG_VIEW_NUMBER, 0);// w  ww  .  ja v a 2s.  c om
    mCurrentFragment.setArguments(args);

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

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

public void stopTimer(View view) {
    m_timerMenuItem.setTitle("Set Timer");
    timerRunning = false;/*  ww w .  j  a v  a 2  s.c o m*/
    mCurrentFragment = new CodersBestFragment(R.layout.fragment_timer);
    Bundle args = new Bundle();
    mCurrentFragment.setArguments(args);
    FragmentManager fragmentManager = getFragmentManager();
    fragmentManager.beginTransaction()
            .replace(com.HACK.codersbestfriend.R.id.content_frame, mCurrentFragment, "fragmentTag").commit();
}

From source file:com.royclarkson.springagram.MainActivity.java

@Override
public void onPhotoAddToGallerySelected(int position) {
    ItemResource item = this.photos.get(position);
    String itemGalleryUrl = item.getLink(ItemResource.REL_GALLERY).getHref();
    PhotoAddToGalleryFragment photoAddToGalleryFragment = PhotoAddToGalleryFragment.newInstance(itemGalleryUrl);
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction transaction = fragmentManager.beginTransaction()
            .add(R.id.container, photoAddToGalleryFragment).addToBackStack(null);
    transaction.commit();//from  w  w w  .jav  a 2  s  .  c  o  m
}

From source file:com.royclarkson.springagram.MainActivity.java

@Override
public void onGallerySelected(int position) {
    GalleryResource gallery = this.galleries.get(position);
    String url = gallery.getLink(GalleryResource.REL_ITEMS).getHref();
    GalleryPhotoListFragment galleryPhotoListFragment = GalleryPhotoListFragment.newInstance(url);
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction transaction = fragmentManager.beginTransaction()
            .add(R.id.container, galleryPhotoListFragment).addToBackStack(null);
    transaction.commit();/*from w w  w.  ja v a 2  s.c  o m*/
}

From source file:com.unicamp.br.mo409.controller.MainActivity.java

public void callNewFragment(int position, Fragment fragment) {
    // update the main content by replacing fragments
    Bundle args = new Bundle();
    fragment.setArguments(args);/*from  www  . ja  v  a  2  s.  com*/
    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(mTitles[position]);
    mDrawerLayout.closeDrawer(mDrawerList);
}

From source file:it.meet.activities.MainActivity.java

public void selectItem(int position) {
    // update the main content by replacing fragments
    Log.w("Position", "position=" + position);

    if (position == 0 && !(currentFragment instanceof SearchFragment)) {
        if (searchFragment == null) {
            searchFragment = new SearchFragment();
        }//from w w w  .  ja va2 s . co m
        currentFragment = searchFragment;
        FragmentManager fragmentManager = getFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.content_frame, searchFragment).commit();
    } else if (position == 1 && !(currentFragment instanceof ConversationsListFragment)) {
        ConversationsListFragment conversationsFragment = new ConversationsListFragment();
        currentFragment = conversationsFragment;
        FragmentManager fragmentManager = getFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.content_frame, conversationsFragment).commit();
    } else if (position == 2 && !(currentFragment instanceof FriendsListFragment)) {
        FriendsListFragment friendsFragment = new FriendsListFragment();
        currentFragment = friendsFragment;
        FragmentManager fragmentManager = getFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.content_frame, friendsFragment).commit();
    } else if (position == 3 && !(currentFragment instanceof FriendRequestsFragment)) {
        FriendRequestsFragment friendRequestFragment = new FriendRequestsFragment();
        currentFragment = friendRequestFragment;
        FragmentManager fragmentManager = getFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.content_frame, friendRequestFragment).commit();
    } else if (position == 4 && !(currentFragment instanceof BlackListFragment)) {
        BlackListFragment blackListFragment = new BlackListFragment();
        currentFragment = blackListFragment;
        FragmentManager fragmentManager = getFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.content_frame, blackListFragment).commit();
    } else if (position == 5 && !(currentFragment instanceof FavoritePlacesFragment)) {
        FavoritePlacesFragment favoritePlacesFragment = new FavoritePlacesFragment();
        currentFragment = favoritePlacesFragment;
        FragmentManager fragmentManager = getFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.content_frame, favoritePlacesFragment).commit();
    } else if (position == 6 && !(currentFragment instanceof MyProfileFragment)) {
        MyProfileFragment profileFragment = new MyProfileFragment();
        currentFragment = profileFragment;
        FragmentManager fragmentManager = getFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.content_frame, profileFragment).commit();
    } else if (position == 7 && !(currentFragment instanceof SettingsFragment)) {
        SettingsFragment settingsFragment = new SettingsFragment();
        currentFragment = settingsFragment;
        FragmentManager fragmentManager = getFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.content_frame, settingsFragment).commit();
    } else if (position == 8) {
        //return to loginFragment
        this.askLogOut(this);
    } else if (position == 9) {
        askExit();
    }
    mDrawerList.setItemChecked(position, true);
    mDrawerLayout.closeDrawer(mDrawerList);

}

From source file:my.madet.uniteninfo.MainHome.java

/**
 * Diplaying fragment view for selected nav drawer list item
 * *//*from www.j  a v  a 2 s. com*/
private void displayView(int position) {
    // update the main content by replacing fragments
    Fragment fragment = null;
    switch (position) {
    case 0:
        fragment = new HomeFragment();
        break;
    case 1:
        fragment = new ClassNoticesFragment();
        break;
    case 2:
        fragment = new LedgerBalanceFragment(); //ledger
        break;
    case 3:
        fragment = new ResultFragment();
        break;
    case 4:
        fragment = new ScorunFragment();
        break;
    case 5:
        fragment = new TimetableFragment();
        break;
    case 6:
        fragment = new TimetableFragmentWeb();
        break;
    case 7:
        fragment = new OpenVPN();
        break;
    case 8:
        fragment = new PreferenceFragment();
        break;
    case 9:
        fragment = new AboutFragment();
        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]);
        setTitle("Uniten Student Info");
        mDrawerLayout.closeDrawer(mDrawerList);
    } else {
        // error in creating fragment
        Log.e("MainActivity", "Error in creating fragment");
    }
}