List of usage examples for android.app FragmentTransaction replace
public abstract FragmentTransaction replace(@IdRes int containerViewId, Fragment fragment, String tag);
From source file:it.mobistego.MainActivity.java
@Override public void onDelete() { FragmentManager ft = getFragmentManager(); FragmentTransaction tx = ft.beginTransaction(); MainFragment mainF = new MainFragment(); tx.replace(R.id.listFragment, mainF, Constants.CONTAINER); tx.commit();/*from w w w . ja v a 2 s .c o m*/ }
From source file:com.github.cpmproto.categorystepfragment.base.GuidedStepListFragment.java
/** * Adds the specified GuidedStepListFragment as content of Activity; no backstack entry is added so * the activity will be dismissed when BACK key is pressed. The method is typically called in * Activity.onCreate() when savedInstanceState is null. When savedInstanceState is not null, * the Activity is being restored, do not call addAsRoot() to duplicate the Fragment restored * by FragmentManager./*from w w w .j a va 2s .c o m*/ * {@link #UI_STYLE_ACTIVITY_ROOT} is assigned. * <p/> * Note: currently fragments added using this method must be created programmatically rather * than via XML. * * @param activity The Activity to be used to insert GuidedStepListFragment. * @param fragment The GuidedStepListFragment to be inserted into the fragment stack. * @param id The id of container to add GuidedStepListFragment, can be android.R.id.content. * @return The ID returned by the call FragmentTransaction.commit, or -1 there is already * GuidedStepListFragment. */ public static int addAsRoot(Activity activity, GuidedStepListFragment fragment, int id) { // Workaround b/23764120: call getDecorView() to force requestFeature of ActivityTransition. activity.getWindow().getDecorView(); FragmentManager fragmentManager = activity.getFragmentManager(); if (fragmentManager.findFragmentByTag(TAG_LEAN_BACK_ACTIONS_FRAGMENT) != null) { Log.w(TAG, "Fragment is already exists, likely calling " + "addAsRoot() when savedInstanceState is not null in Activity.onCreate()."); return -1; } FragmentTransaction ft = fragmentManager.beginTransaction(); fragment.setUiStyle(UI_STYLE_ACTIVITY_ROOT); return ft.replace(id, fragment, TAG_LEAN_BACK_ACTIONS_FRAGMENT).commit(); }
From source file:it.mobistego.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_fragment); init();// ww w. java 2 s .co m FragmentManager ft = getFragmentManager(); FragmentTransaction tx = ft.beginTransaction(); MainFragment mainF = new MainFragment(); tx.replace(R.id.listFragment, mainF, Constants.CONTAINER); tx.commit(); }
From source file:org.yuzhiqiang.itsmine.MainActivity.java
@Override public void onNavigationDrawerItemSelected(int position) { // update the main content by replacing fragments FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); switch (position) { case 0:/* w ww .j a va 2 s. com*/ fragmentTransaction.replace(R.id.container, new ItemListFragment(), ALL_ITEMS); break; case 1: fragmentTransaction.replace(R.id.container, new ItemListFragment(), TOP_LEVEL_ITEMS); break; case 2: fragmentTransaction.replace(R.id.container, new CategoryFragment()); break; case 3: fragmentTransaction.replace(R.id.container, new SettingsFragment()); break; } fragmentTransaction.commit(); }
From source file:com.pickr.activities.FlickrActivity.java
/** * Show a fragment in the main view//from w w w . ja v a2 s. c o m * * @param item The fragment to display */ private void showFragment(Item<FlickrFragment> item) { FlickrFragment fragment = item.getValue(); FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction transaction = fragmentManager.beginTransaction(); transaction.replace(R.id.flickrFragmentsLayout, fragment, fragment.getClass().getSimpleName()); transaction.commit(); getActionBar().setTitle(fragment.getTitle()); mCurrentFragment = fragment; for (Item<FlickrFragment> item2 : mDrawerListItems) { item2.setSelected(false); } item.setSelected(true); mDrawerListAdapter.notifyDataSetChanged(); }
From source file:org.peterbaldwin.vlcremote.app.PickServerActivity.java
@SuppressWarnings("unchecked") public <T extends android.app.Fragment> T findOrReplaceFragment(int res, String tag, Class<T> fragmentClass) { try {/* w w w. ja va2 s .co m*/ FragmentManager fm = getFragmentManager(); T fragment = (T) fm.findFragmentByTag(tag); if (fragment == null) { fragment = fragmentClass.newInstance(); FragmentTransaction fragmentTransaction = fm.beginTransaction(); fragmentTransaction.replace(res, fragment, tag); fragmentTransaction.commit(); fm.executePendingTransactions(); } return fragment; } catch (InstantiationException e) { throw new IllegalArgumentException(e); } catch (IllegalAccessException e) { throw new IllegalArgumentException(e); } }
From source file:edu.scranton.fisherc5.busybusy.MainActivity.java
public void setDailyViewFragment(Bundle args) { Fragment dailyViewFrag = new DailyViewFragment(); dailyViewFrag.setArguments(args);/*from w ww .j av a 2 s . co m*/ SimpleDateFormat format = new SimpleDateFormat("MMMM d, yyyy"); Calendar temp = new GregorianCalendar(); temp.setTimeInMillis(args.getLong(Keys.SELECTED_DATE_KEY)); getActionBar().setTitle(format.format(temp.getTime())); mDateInActionBar = true; //SET TRANSACTION. ADD TO BACK STACK FragmentTransaction transaction = getFragmentManager().beginTransaction(); transaction.replace(R.id.content_frame, dailyViewFrag, "PRE_COMPARE"); transaction.addToBackStack("PRE_COMPARE_PUSH"); transaction.commit(); }
From source file:de.lebenshilfe_muenster.uk_gebaerden_muensterland.activities.MainActivity.java
private void setFragment(Fragment fragment, String actionBarTitle) { Log.d(TAG, "setFragment: " + actionBarTitle + StringUtils.SPACE + hashCode()); final FragmentTransaction transaction = getFragmentManager().beginTransaction(); transaction.replace(R.id.content_frame, fragment, actionBarTitle); transaction.addToBackStack(actionBarTitle); transaction.commit();//w w w. j a va 2s .c o m }
From source file:com.tapchatapp.android.app.activity.MainActivity.java
@Override public void loadFragments() { setContentView(R.layout.activity_main); MainFragment fragment = (MainFragment) getFragmentManager().findFragmentByTag("main"); if (fragment == null) { FragmentTransaction transaction = getFragmentManager().beginTransaction(); transaction.replace(R.id.content, new MainFragment(), "main"); transaction.commit();/* w ww . j a v a 2s. c om*/ } }
From source file:com.bradbergeron.splitviewcontrollerdemo.activities.MainActivity.java
@Override public void onDrawerItemSelected(final DrawerFragment.FragmentDrawerItem fragmentDrawerItem) { if (mDrawerLayout.isDrawerOpen(Gravity.START)) { mDrawerLayout.closeDrawer(Gravity.START); }// w w w.j a v a2 s.co m final FragmentManager fragmentManager = getFragmentManager(); final String fragmentClassName = fragmentDrawerItem.getFragmentClass().getName(); Fragment newFragment = fragmentManager.findFragmentByTag(fragmentClassName); if (newFragment == null) { newFragment = Fragment.instantiate(this, fragmentClassName); } else if (newFragment.isAdded()) { return; } else if (fragmentDrawerItem.isDefaultItem() && fragmentManager.getBackStackEntryCount() > 0) { fragmentManager.popBackStack("Drawer", FragmentManager.POP_BACK_STACK_INCLUSIVE); } final FragmentTransaction transaction = fragmentManager.beginTransaction(); transaction.replace(R.id.content, newFragment, fragmentClassName); if (!fragmentDrawerItem.isDefaultItem()) { transaction.addToBackStack("Drawer"); } transaction.commit(); }