List of usage examples for android.app FragmentManager beginTransaction
public abstract FragmentTransaction beginTransaction();
From source file:com.lgallardo.youtorrentcontroller.ItemstFragment.java
private void newDetailsFragment(int position) { detailsFragment = new TorrentDetailsFragment(); // Get torrent from MainActivity detailsFragment.setTorrent(MainActivity.lines[position]); detailsFragment.setPosition(position); if (detailsFragment != null) { FragmentManager fragmentManager = getFragmentManager(); if (getActivity().findViewById(R.id.one_frame) != null) { fragmentManager.beginTransaction() .replace(this.getSecondFragmentContainer(), detailsFragment, "firstFragment") .addToBackStack("secondFragment").commit(); // Change toolbar home button behaviour originalListener = MainActivity.drawerToggle.getToolbarNavigationClickListener(); MainActivity.drawerToggle.setDrawerIndicatorEnabled(false); MainActivity.drawerToggle.setHomeAsUpIndicator(R.drawable.ic_drawer); MainActivity.drawerToggle.setToolbarNavigationClickListener(new View.OnClickListener() { @Override//from ww w .j av a 2 s .c om public void onClick(View v) { // Disable refreshing MainActivity.disableRefreshSwipeLayout(); // Set default toolbar behaviour ((MainActivity) getActivity()).getSupportActionBar().setDisplayShowTitleEnabled(true); MainActivity.drawerToggle.setDrawerIndicatorEnabled(true); MainActivity.drawerToggle.setToolbarNavigationClickListener(originalListener); ((MainActivity) getActivity()).setSelectionAndTitle(MainActivity.currentState); // Show herderInfo in phone's view if (getActivity().findViewById(R.id.one_frame) != null) { if (MainActivity.headerInfo != null) { if (MainActivity.header) { MainActivity.headerInfo.setVisibility(View.VISIBLE); } else { MainActivity.headerInfo.setVisibility(View.GONE); } } } FragmentManager fm = getFragmentManager(); fm.popBackStack(); } }); } else { fragmentManager.beginTransaction() .replace(this.getSecondFragmentContainer(), detailsFragment, "secondFragment") .addToBackStack("secondFragment").commit(); } } }
From source file:fr.cph.chicago.activity.MainActivity.java
@Override public final void onNavigationDrawerItemSelected(final int position) { int oldPosition = mCurrentPosition; mCurrentPosition = position;/*from ww w . j a v a 2s . c o m*/ // update the main content by replacing fragments final FragmentManager fragmentManager = getFragmentManager(); final FragmentTransaction ft = fragmentManager.beginTransaction(); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); switch (position) { case POSITION_FAVORITES: if (mFavoritesFragment == null) { mFavoritesFragment = FavoritesFragment.newInstance(position + 1); } if (!this.isFinishing()) { ft.replace(R.id.container, mFavoritesFragment).commit(); } break; case POSITION_TRAIN: if (mTrainFragment == null) { mTrainFragment = TrainFragment.newInstance(position + 1); } if (!this.isFinishing()) { ft.replace(R.id.container, mTrainFragment).commit(); } break; case POSITION_BUS: if (mBusFragment == null) { mBusFragment = BusFragment.newInstance(position + 1); } if (!this.isFinishing()) { ft.replace(R.id.container, mBusFragment).commit(); } break; case POSITION_DIVVY: if (mBikeFragment == null) { mBikeFragment = BikeFragment.newInstance(position + 1); } if (!this.isFinishing()) { ft.replace(R.id.container, mBikeFragment).commit(); } break; case POSITION_NEARBY: if (mNearbyFragment == null) { mNearbyFragment = NearbyFragment.newInstance(position + 1); if (!this.isFinishing()) { ft.replace(R.id.container, mNearbyFragment).commit(); } } else { if (oldPosition == 4) { fragmentManager.beginTransaction().commit(); } else { if (!this.isFinishing()) { ft.replace(R.id.container, mNearbyFragment).commit(); } } } break; case POSITION_ALERTS: if (mAlertFragment == null) { mAlertFragment = AlertFragment.newInstance(position + 1); } if (!this.isFinishing()) { ft.replace(R.id.container, mAlertFragment).commit(); } break; case POSITION_MAP: if (mMapFragment == null) { mMapFragment = MapFragment.newInstance(position + 1); } if (!this.isFinishing()) { ft.replace(R.id.container, mMapFragment).commit(); } break; case POSITION_SETTINGS: if (mSettingsFragment == null) { mSettingsFragment = SettingsFragment.newInstance(position + 1); } if (!this.isFinishing()) { ft.replace(R.id.container, mSettingsFragment).commit(); } break; } }
From source file:koma.movieapp.ui.SearchActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_search); Toolbar toolbar = getActionBarToolbar(); toolbar.setTitle(R.string.title_search); toolbar.setNavigationIcon(R.drawable.ic_up); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override//from w w w . ja va2s . co m public void onClick(View view) { navigateUpToFromChild(SearchActivity.this, IntentCompat .makeMainActivity(new ComponentName(SearchActivity.this, PopularMoviesActivity.class))); } }); FragmentManager fm = getFragmentManager(); mMoviesFragment = (MoviesFragment) fm.findFragmentById(R.id.fragment_container); String query = getIntent().getStringExtra(SearchManager.QUERY); query = query == null ? "" : query; mQuery = query; if (mMoviesFragment == null) { mMoviesFragment = new MoviesFragment(); //Bundle args = intentToFragmentArguments(getIntent()); Bundle args = new Bundle(); args.putString("title", "Search"); args.putString("searchString", query); mMoviesFragment.setArguments(args); fm.beginTransaction().add(R.id.fragment_container, mMoviesFragment).commit(); } if (mSearchView != null) { mSearchView.setQuery(query, false); } overridePendingTransition(0, 0); }
From source file:com.blue.leaves.util.task.SugarTask.java
private void registerHookToContext(@NonNull android.support.v4.app.Fragment fragment) { android.support.v4.app.FragmentManager manager = fragment.getChildFragmentManager(); HookSupportFragment hookSupportFragment = (HookSupportFragment) manager.findFragmentByTag(TAG_HOOK); if (hookSupportFragment == null) { hookSupportFragment = new HookSupportFragment(); manager.beginTransaction().add(hookSupportFragment, TAG_HOOK).commitAllowingStateLoss(); }/*from w w w. ja va 2s. c o m*/ }
From source file:pffy.mobile.bran.BranActivity.java
@Override public void onNavigationDrawerItemSelected(int position) { sCategoryKey = position;//from w w w. ja va 2s .c o m // if new category chosen, select the first item in the list sMenuItem = 0; // update the main content by replacing fragments FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction() .replace(R.id.framelayout_container, PlaceholderFragment.newInstance(position + 1)).commit(); }
From source file:com.blue.leaves.util.task.SugarTask.java
private void registerHookToContext(@NonNull FragmentActivity activity) { android.support.v4.app.FragmentManager manager = activity.getSupportFragmentManager(); HookSupportFragment hookSupportFragment = (HookSupportFragment) manager.findFragmentByTag(TAG_HOOK); if (hookSupportFragment == null) { hookSupportFragment = new HookSupportFragment(); manager.beginTransaction().add(hookSupportFragment, TAG_HOOK).commitAllowingStateLoss(); }// w w w. j ava2 s . co m }
From source file:com.mariogrip.octodroid.mainActivity.java
private void selectItem(int position) { pos = position;// w w w . j a v a 2 s. c o m Fragment fragment = new main_card(); if (betamode) { fragment = new main_card_BETA(); switch (position) { case 0: fragment = new main_card_BETA(); break; case 6: fragment = new main_card_BETA(); pos = 0; position = 0; Intent i = new Intent(this, settings.class); startActivityForResult(i, RESULT_SETTINGS); break; case 1: fragment = new temp_card(); break; case 2: fragment = new cont_card(); break; case 3: fragment = new file_card(); break; case 4: fragment = new con_card(); break; case 5: fragment = new custom_card(); break; default: break; } } else { fragment = new main_card(); switch (position) { case 0: fragment = new main_card(); break; case 6: fragment = new main_card(); pos = 0; position = 0; Intent i = new Intent(this, settings.class); startActivityForResult(i, RESULT_SETTINGS); break; case 1: fragment = new temp_card(); break; case 2: fragment = new cont_card(); break; case 3: fragment = new file_card(); break; case 4: fragment = new con_card(); break; case 5: fragment = new custom_card(); break; default: break; } } Bundle args = new Bundle(); args.putInt(PlanetFragment.ARG_PLANET_NUMBER, position); fragment.setArguments(args); FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit(); // update selected item and title, then close the drawer nawList.setItemChecked(position, true); setTitle(nawTitle[position]); nawlay.closeDrawer(nawList); }
From source file:com.sintef_energy.ubisolar.activities.DrawerActivity.java
/** * Helper method to add fragments to the view. * * @param fragment Fragment to swap in// ww w. ja va2s . c o m * @param animate True if swap shall have an animation * @param addToBackStack True if the Fragment shall go to the back stack * @param tag String for the back stack */ public void addFragment(Fragment fragment, boolean animate, boolean addToBackStack, String tag) { FragmentManager manager = getFragmentManager(); FragmentTransaction ft = manager.beginTransaction(); if (animate) { ft.setCustomAnimations(android.R.anim.slide_in_left, android.R.anim.slide_out_right, // Pop enter android.R.anim.fade_in, android.R.anim.fade_out); } if (addToBackStack) { ft.addToBackStack(tag); } ft.replace(R.id.container, fragment, tag); ft.commit(); }
From source file:com.roymam.android.nilsplus.ui.NiLSActivity.java
public void replaceFragment(Fragment fragment) { this.fragment = fragment; FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).addToBackStack("Fragment") .commit();/*from w w w . ja va2 s . co m*/ }
From source file:no.digipost.android.gui.MainContentActivity.java
private void selectItem(int content) { ContentFragment contentFragment = DocumentFragment.newInstance(ApplicationConstants.MAILBOX); if (account != null) { try {//from ww w . j a va2 s. co m int inboxReceiptsAndFolders = (numberOfFolders + ApplicationConstants.numberOfStaticFolders); if (content == ApplicationConstants.MAILBOX) { contentFragment = DocumentFragment.newInstance(ApplicationConstants.MAILBOX); } else if (content > ApplicationConstants.FOLDERS_LABEL && content < inboxReceiptsAndFolders) { contentFragment = DocumentFragment.newInstance(content); } else if (selectAccountItem(content)) { return; } else if (folders != null && content == inboxReceiptsAndFolders) { showCreateEditDialog(content, false); return; } } catch (Exception e) { e.printStackTrace(); } } FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.main_content_frame, contentFragment).commit(); drawerList.setItemChecked(content, true); drawer.closeDrawers(); }