Refine search
FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction transaction = fragmentManager.beginTransaction(); transaction.setCustomAnimations(R.anim.enter, R.anim.exit, R.anim.pop_enter, R.anim.pop_exit); CustomFragment newCustomFragment = CustomFragment.newInstance(); transaction.replace(R.id.fragment_container, newCustomFragment ); transaction.addToBackStack(null); transaction.commit();
public class MyActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); FragmentManager fm = getFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); Fragment fragOne = new MyFragment(); Bundle arguments = new Bundle(); arguments.putBoolean("shouldYouCreateAChildFragment", true); fragOne.setArguments(arguments); ft.add(R.id.main_frag_container, fragOne); ft.commit(); } }
if(!isFinishing()) { FragmentManager fm = getSupportFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); DummyFragment dummyFragment = DummyFragment.newInstance(); ft.add(R.id.dummy_fragment_layout, dummyFragment); ft.commitAllowingStateLoss(); }
FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_right); DetailsFragment newFragment = DetailsFragment.newInstance(); ft.replace(R.id.details_fragment_container, newFragment, "detailFragment"); // Start the animated transition. ft.commit();
private final static String TAG_FRAGMENT = "TAG_FRAGMENT"; private void showFragment() { final Myfragment fragment = new MyFragment(); final FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); transaction.replace(R.id.fragment, fragment, TAG_FRAGMENT); transaction.addToBackStack(null); transaction.commit(); } @Override public void onBackPressed() { final Myfragment fragment = (Myfragment) getSupportFragmentManager().findFragmentByTag(TAG_FRAGMENT); if (fragment.allowBackPressed()) { // and then you define a method allowBackPressed with the logic to allow back pressed or not super.onBackPressed(); } }
@Test public void testConfigurationChanged() { when(itemManager.getStories(any(), eq(ItemManager.MODE_DEFAULT))).thenReturn(new Item[]{new TestItem() { }}); Bundle args = new Bundle(); args.putString(ListFragment.EXTRA_ITEM_MANAGER, HackerNewsClient.class.getName()); args.putString(ListFragment.EXTRA_FILTER, ItemManager.TOP_FETCH_MODE); Fragment fragment = Fragment.instantiate(activity, ListFragment.class.getName(), args); activity.getSupportFragmentManager() .beginTransaction() .add(android.R.id.list, fragment) .commit(); verify(itemManager).getStories(any(), eq(ItemManager.MODE_DEFAULT)); reset(itemManager); Bundle state = new Bundle(); fragment.onSaveInstanceState(state); fragment.onActivityCreated(state); // should not trigger another data request verify(itemManager, never()).getStories(any(String.class), eq(ItemManager.MODE_DEFAULT)); controller.pause().stop().destroy(); }
private void displayPlaceInfoFragment(Place place) { PlaceInfoFragment placeInfoFragment = PlaceInfoFragment.newInstance(); Bundle bundle = new Bundle(); bundle.putParcelable(PlaceInfoFragment.EXTRA_PLACE, place); placeInfoFragment.setArguments(bundle); getSupportFragmentManager() .beginTransaction() .add(R.id.fragment_placeholder, placeInfoFragment, "details") .addToBackStack(place.get(Place.NAME)) .commit(); }
@TargetApi(21) public static void navigateToAlbum(Activity context, long albumID, Pair<View, String> transitionViews) { FragmentTransaction transaction = ((AppCompatActivity) context).getSupportFragmentManager().beginTransaction(); Fragment fragment; transaction.setCustomAnimations(R.anim.activity_fade_in, R.anim.activity_fade_out, R.anim.activity_fade_in, R.anim.activity_fade_out); fragment = AlbumDetailFragment.newInstance(albumID, false, null); transaction.hide(((AppCompatActivity) context).getSupportFragmentManager().findFragmentById(R.id.fragment_container)); transaction.add(R.id.fragment_container, fragment); transaction.addToBackStack(null).commit(); }
private void switchFragment(Fragment fragment, User organization) { if (organization != null) { Bundle args = new Bundle(); args.putParcelable("org", organization); fragment.setArguments(args); } FragmentManager manager = getSupportFragmentManager(); manager.beginTransaction().replace(R.id.container, fragment).commit(); drawerLayout.closeDrawer(GravityCompat.START); currentFragment = fragment; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_preferences); setTitle(getIntent().getIntExtra(EXTRA_TITLE, 0)); setSupportActionBar((Toolbar) findViewById(R.id.toolbar)); //noinspection ConstantConditions getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_TITLE); if (savedInstanceState == null) { Bundle args = new Bundle(); args.putInt(EXTRA_PREFERENCES, getIntent().getIntExtra(EXTRA_PREFERENCES, 0)); getSupportFragmentManager() .beginTransaction() .add(R.id.content_frame, Fragment.instantiate(this, SettingsFragment.class.getName(), args), SettingsFragment.class.getName()) .commit(); } }
@Override protected void onCreate(Bundle savedInstanceState) { setTheme(R.style.AppTheme); super.onCreate(savedInstanceState); if (savedInstanceState == null) { WebItem item = getIntent().getParcelableExtra(EXTRA_ITEM); Bundle args = new Bundle(); args.putParcelable(WebFragment.EXTRA_ITEM, item); fragment = (WebFragment) Fragment.instantiate(this, WebFragment.class.getName(), args); getSupportFragmentManager() .beginTransaction() .add(android.R.id.content, fragment, WebFragment.class.getName()) .commit(); } else { fragment = (WebFragment) getSupportFragmentManager().findFragmentByTag(WebFragment.class.getName()); } } }
@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); FragmentManager fm = getChildFragmentManager(); SupportMapFragment mapFragment = (SupportMapFragment) fm.findFragmentByTag("mapFragment"); if (mapFragment == null) { mapFragment = new SupportMapFragment(); FragmentTransaction ft = fm.beginTransaction(); ft.add(R.id.mapFragmentContainer, mapFragment, "mapFragment"); ft.commit(); fm.executePendingTransactions(); } mapFragment.getMapAsync(callback); }
@Override public void destroyItem(ViewGroup container, int position, Object object) { FragmentManager manager = ((Fragment)object).getFragmentManager(); FragmentTransaction trans = manager.beginTransaction(); trans.remove((Fragment)object); trans.commit(); }
CaldroidFragment caldroidFragment = new CaldroidFragment(); Bundle args = new Bundle(); Calendar cal = Calendar.getInstance(); args.putInt(CaldroidFragment.MONTH, cal.get(Calendar.MONTH) + 1); args.putInt(CaldroidFragment.YEAR, cal.get(Calendar.YEAR)); caldroidFragment.setArguments(args); FragmentTransaction t = getSupportFragmentManager().beginTransaction(); t.replace(R.id.calendar1, caldroidFragment); t.commit();
@Override protected void onReady(Bundle state) { if (state!=null) { isInResolution=state.getBoolean(STATE_IN_RESOLUTION, false); } fragment= (WeatherFragment)getSupportFragmentManager().findFragmentById(android.R.id.content); if (fragment==null) { fragment=new WeatherFragment(); getSupportFragmentManager().beginTransaction() .add(android.R.id.content, fragment).commit(); } if (!isInResolution) { isInResolution=true; LocationSettingsRequest request=new LocationSettingsRequest.Builder() .addLocationRequest(LocationRequest.create()) .build(); LocationServices.getSettingsClient(this) .checkLocationSettings(request) .addOnCompleteListener(this::handleSettingsResponse); } }
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate( R.layout.fragment_artist_detail, container, false); artistArt = (ImageView) rootView.findViewById(R.id.artist_art); collapsingToolbarLayout = (CollapsingToolbarLayout) rootView.findViewById(R.id.collapsing_toolbar); appBarLayout = (AppBarLayout) rootView.findViewById(R.id.app_bar); if (getArguments().getBoolean("transition")) { artistArt.setTransitionName(getArguments().getString("transition_name")); } toolbar = (Toolbar) rootView.findViewById(R.id.toolbar); setupToolbar(); setUpArtistDetails(); getChildFragmentManager().beginTransaction().replace(R.id.container, ArtistMusicFragment.newInstance(artistID)).commit(); return rootView; }
private void replaceFragment() { Fragment fragment = new HorizontalGalleryFragment(); getSupportFragmentManager() .beginTransaction() .replace(R.id.fragment_container, fragment) .commit(); }
private void replaceFragment (Fragment fragment){ String backStateName = fragment.getClass().getName(); String fragmentTag = backStateName; FragmentManager manager = getSupportFragmentManager(); boolean fragmentPopped = manager.popBackStackImmediate (backStateName, 0); if (!fragmentPopped && manager.findFragmentByTag(fragmentTag) == null){ //fragment not in back stack, create it. FragmentTransaction ft = manager.beginTransaction(); ft.replace(R.id.content_frame, fragment, fragmentTag); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); ft.addToBackStack(backStateName); ft.commit(); } }
@Override public void onCreate(Bundle savedInstanceState) { if (PreferencesUtility.getInstance(this).getTheme().equals("dark")) setTheme(R.style.AppThemeNormalDark); else if (PreferencesUtility.getInstance(this).getTheme().equals("black")) setTheme(R.style.AppThemeNormalBlack); super.onCreate(savedInstanceState); setContentView(R.layout.activity_settings); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); action = getIntent().getAction(); if (action.equals(Constants.SETTINGS_STYLE_SELECTOR)) { getSupportActionBar().setTitle(R.string.now_playing); String what = getIntent().getExtras().getString(Constants.SETTINGS_STYLE_SELECTOR_WHAT); Fragment fragment = StyleSelectorFragment.newInstance(what); FragmentManager fragmentManager = getSupportFragmentManager(); fragmentManager.beginTransaction() .add(R.id.fragment_container, fragment).commit(); } else { getSupportActionBar().setTitle(R.string.settings); PreferenceFragment fragment = new SettingsFragment(); android.app.FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction() .replace(R.id.fragment_container, fragment).commit(); } }
@Override protected String doInBackground(String... params) { QuickControlsFragment fragment1 = new QuickControlsFragment(); FragmentManager fragmentManager1 = getSupportFragmentManager(); fragmentManager1.beginTransaction() .replace(R.id.quickcontrols_container, fragment1).commitAllowingStateLoss(); return "Executed"; }