List of usage examples for android.app FragmentManager beginTransaction
public abstract FragmentTransaction beginTransaction();
From source file:com.esri.android.mapsapp.MapFragment.java
/** * Opens the map represented by the specified portal item or if null, opens * a default map.//from w w w.j a v a 2 s .co m */ public void showMap(String portalItemId, String basemapPortalItemId) { // remove existing MapFragment explicitly, simply replacing it can cause // the app to freeze when switching basemaps FragmentTransaction transaction; FragmentManager fragmentManager = getFragmentManager(); Fragment currentMapFragment = fragmentManager.findFragmentByTag(MapFragment.TAG); if (currentMapFragment != null) { transaction = fragmentManager.beginTransaction(); transaction.remove(currentMapFragment); transaction.commit(); } MapFragment mapFragment = MapFragment.newInstance(portalItemId, basemapPortalItemId); transaction = fragmentManager.beginTransaction(); transaction.replace(R.id.maps_app_activity_content_frame, mapFragment, MapFragment.TAG); transaction.addToBackStack(null); transaction.commit(); getActivity().invalidateOptionsMenu(); // reload the options menu }
From source file:co.taqat.call.LinphoneActivity.java
private void changeFragment(Fragment newFragment, FragmentsAvailable newFragmentType, boolean withoutAnimation) { FragmentManager fm = getFragmentManager(); FragmentTransaction transaction = fm.beginTransaction(); /*/* w w w . j a v a 2 s .co m*/ if (!withoutAnimation && currentFragment.shouldAnimate()) { if (newFragmentType.isRightOf(currentFragment)) { transaction.setCustomAnimations(R.anim.slide_in_right_to_left, R.anim.slide_out_right_to_left, R.anim.slide_in_left_to_right, R.anim.slide_out_left_to_right); } else { transaction.setCustomAnimations(R.anim.slide_in_left_to_right, R.anim.slide_out_left_to_right, R.anim.slide_in_right_to_left, R.anim.slide_out_right_to_left); } }*/ if (newFragmentType != FragmentsAvailable.DIALER && newFragmentType != FragmentsAvailable.CONTACTS_LIST && newFragmentType != FragmentsAvailable.CHAT_LIST && newFragmentType != FragmentsAvailable.HISTORY_LIST) { transaction.addToBackStack(newFragmentType.toString()); } else { while (fm.getBackStackEntryCount() > 0) { fm.popBackStackImmediate(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); } } transaction.replace(R.id.fragmentContainer, newFragment, newFragmentType.toString()); transaction.commitAllowingStateLoss(); fm.executePendingTransactions(); currentFragment = newFragmentType; }
From source file:android.support.v17.leanback.app.BrowseFragment.java
private void swapToMainFragment() { final VerticalGridView gridView = mHeadersFragment.getVerticalGridView(); if (isShowingHeaders() && gridView != null && gridView.getScrollState() != RecyclerView.SCROLL_STATE_IDLE) { // if user is scrolling HeadersFragment, swap to empty fragment and wait scrolling // finishes. getChildFragmentManager().beginTransaction().replace(R.id.scale_frame, new Fragment()).commit(); gridView.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override//from w w w .ja v a2 s. com public void onScrollStateChanged(RecyclerView recyclerView, int newState) { if (newState == RecyclerView.SCROLL_STATE_IDLE) { gridView.removeOnScrollListener(this); FragmentManager fm = getChildFragmentManager(); Fragment currentFragment = fm.findFragmentById(R.id.scale_frame); if (currentFragment != mMainFragment) { fm.beginTransaction().replace(R.id.scale_frame, mMainFragment).commit(); } } } }); } else { // Otherwise swap immediately getChildFragmentManager().beginTransaction().replace(R.id.scale_frame, mMainFragment).commit(); } }
From source file:com.sdspikes.fireworks.FireworksActivity.java
private void addHandFragment(FragmentManager fm, GameState.HandNode node, String playerId, String playerName, int id) { try {/*from w w w. j ava 2s . c om*/ Log.d(TAG, node.encodeNode().toString()); } catch (JSONException e) { e.printStackTrace(); } HandFragment handFragment = HandFragment.newInstance(node.hand, playerId, playerName, playerId == mMyId); fragments.put(playerId, handFragment); // TODO(sdspikes): previously I just had .commit here and got // java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState fm.beginTransaction().add(id, handFragment).commitAllowingStateLoss(); }
From source file:org.openaccessbutton.openaccessbutton.MainActivity.java
/** * Load and show the corresponding fragment, updating the UI of the navigation drawer at the * same time.//from w ww . ja v a 2s . com */ protected void switchToFragment(int position) { // Switch to the new fragment, instantiating it if a previous instance isn't around FragmentManager fragmentManager = getFragmentManager(); // Find a Fragment of the right class NavigationItem item = mNavigationParser.get(position); if (mFragments[position] == null) { // This is safe because: // - Hardcoded XML: *never* do this from any network-downloaded or user-editable source // - All our fragment constructors need no arguments try { Class<?> fragmentClass = Class.forName(item.className); if (item.className.equals("org.openaccessbutton.openaccessbutton.advocacy.AdvocacyFragment")) { Bundle bundle = new Bundle(); bundle.putString("filename", item.filename); mFragments[position] = new AdvocacyFragment(); mFragments[position].setArguments(bundle); } else { mFragments[position] = (Fragment) fragmentClass.newInstance(); } } catch (ClassNotFoundException e) { mFragments[position] = null; Log.e("openaccess", "exception", e); } catch (IllegalAccessException e) { mFragments[position] = null; Log.e("openaccess", "exception", e); } catch (InstantiationException e) { mFragments[position] = null; Log.e("openaccess", "exception", e); } } mFragment = mFragments[position]; int menuPosition = mNavigationParser.getMenuPositionFromPosition(position); fragmentManager.beginTransaction().replace(R.id.content_frame, mFragment, "mFragment").commit(); // Highlight the selected item, update the title, and close the drawer mDrawerList.setItemChecked(menuPosition, true); setTitle(mNavigationTitles[position]); mDrawerLayout.closeDrawer(mDrawerList); }
From source file:at.alladin.rmbt.android.main.RMBTMainActivity.java
public void showResultsAfterTest(String testUuid) { popBackStackFull();//from ww w . ja va 2 s.c o m final RMBTResultPagerFragment fragment = new RMBTResultPagerFragment(); final Bundle args = new Bundle(); args.putString(RMBTResultPagerFragment.ARG_TEST_UUID, testUuid); fragment.setArguments(args); final FragmentManager fm = getFragmentManager(); final FragmentTransaction ft; ft = fm.beginTransaction(); ft.replace(R.id.fragment_content, fragment, AppConstants.PAGE_TITLE_HISTORY_PAGER); ft.addToBackStack(AppConstants.PAGE_TITLE_HISTORY_PAGER); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); ft.commit(); refreshActionBar(AppConstants.PAGE_TITLE_HISTORY_PAGER); }
From source file:com.afwsamples.testdpc.policy.PolicyManagementFragment.java
private void showFragment(final Fragment fragment) { FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().addToBackStack(PolicyManagementFragment.class.getName()) .replace(R.id.container, fragment).commit(); }
From source file:com.afwsamples.testdpc.policy.PolicyManagementFragment.java
private void showFragment(final Fragment fragment, String tag) { FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().addToBackStack(PolicyManagementFragment.class.getName()) .replace(R.id.container, fragment, tag).commit(); }
From source file:at.alladin.rmbt.android.main.RMBTMainActivity.java
public void showFilter() { final FragmentManager fm = getFragmentManager(); FragmentTransaction ft;/* ww w. j a va2 s. com*/ final Fragment fragment = new RMBTFilterFragment(); ft = fm.beginTransaction(); ft.replace(R.id.fragment_content, fragment, AppConstants.PAGE_TITLE_HISTORY_FILTER); ft.addToBackStack(AppConstants.PAGE_TITLE_HISTORY_FILTER); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); ft.commit(); refreshActionBar(AppConstants.PAGE_TITLE_HISTORY_FILTER); }