Java Code Examples for androidx.fragment.app.FragmentTransaction#hide()
The following examples show how to use
androidx.fragment.app.FragmentTransaction#hide() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FragmentNavigator.java From SAI with GNU General Public License v3.0 | 6 votes |
public void switchTo(String tag) { ensureStateWasRestored(); if (mCurrentFragment != null && tag.equals(mCurrentFragment.getTag())) return; FragmentTransaction transaction = mFragmentManager.beginTransaction(); if (mCurrentFragment != null) { transaction.hide(mCurrentFragment); } Fragment newFragment = mFragmentManager.findFragmentByTag(tag); if (newFragment != null) { transaction.show(newFragment); } else { newFragment = mFragmentFactory.createFragment(tag); transaction.add(mContainerId, newFragment, tag); } mCurrentFragment = newFragment; transaction.commitNow(); }
Example 2
Source File: Main2Activity.java From AndroidGodEye with Apache License 2.0 | 6 votes |
private void showFragment(int index) { FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); List<Fragment> fragments = fragmentManager.getFragments(); for (int i = 0; i < fragments.size(); i++) { fragmentTransaction.hide(fragments.get(i)); } String fragmentName = ""; if (index == 0) { fragmentName = InstallFragment.class.getSimpleName(); } else if (index == 1) { fragmentName = ConsumeFragment.class.getSimpleName(); } else if (index == 2) { fragmentName = ToolsFragment.class.getSimpleName(); } fragmentTransaction.show(Objects.requireNonNull(fragmentManager.findFragmentByTag(fragmentName))).commit(); }
Example 3
Source File: MainActivity.java From QuickDevFramework with Apache License 2.0 | 6 votes |
private void switchFragment(String tag) { /* Fragment 切换 */ FragmentTransaction transaction = mFragmentManager.beginTransaction(); if (fragmentTags.indexOf(tag) < 0) { return; } Fragment showFragment = fragments.get(fragmentTags.indexOf(tag)); Fragment currentFragment = mFragmentManager.findFragmentByTag(currentTag); if (currentFragment != null) { transaction.hide(currentFragment); } if (showFragment.isAdded()) { transaction.show(showFragment); } else { transaction.add(R.id.content_frame, showFragment, tag); transaction.show(showFragment); } transaction.setTransitionStyle(FragmentTransaction.TRANSIT_FRAGMENT_FADE); transaction.commitAllowingStateLoss(); currentTag = tag; }
Example 4
Source File: MainActivity.java From AndroidAll with Apache License 2.0 | 6 votes |
public void fragmentAnimation(View view) { if (mFragmentAnimation == null) { mFragmentAnimation = new FragmentAnimation(); } FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); transaction.setCustomAnimations(R.anim.fragment_expand, R.anim.fragment_collapse); if (mFragmentAnimation.isVisible()) { findViewById(R.id.fragment_container).setVisibility(View.GONE); transaction.hide(mFragmentAnimation); } else { findViewById(R.id.fragment_container).setVisibility(View.VISIBLE); if (mFragmentAnimation.isAdded()) { transaction.show(mFragmentAnimation); } else { transaction.add(R.id.fragment_container, mFragmentAnimation); } } transaction.commit(); }
Example 5
Source File: MainBookListFragment.java From HaoReader with GNU General Public License v3.0 | 6 votes |
private void showFragment(int group) { FragmentTransaction transaction = getChildFragmentManager().beginTransaction(); Fragment from = fragments[this.group]; BookListFragment to = fragments[group]; if (from != null) { transaction.hide(from); } if (to == null) { fragments[group] = to = BookListFragment.newInstance(group); to.setItemClickListenerTwo(getAdapterListener()); } if (!to.isAdded()) { transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN) .add(R.id.book_list_frame, to, getString(BOOK_GROUPS[group])) .commitAllowingStateLoss(); } else if (to.isSupportHidden()) { transaction.setTransition(this.group > group ? FragmentTransaction.TRANSIT_FRAGMENT_OPEN : FragmentTransaction.TRANSIT_FRAGMENT_CLOSE) .show(to) .commitAllowingStateLoss(); } }
Example 6
Source File: FragmentHelper.java From AndroidNavigation with MIT License | 6 votes |
public static void addFragmentToBackStack(@NonNull FragmentManager fragmentManager, int containerId, @NonNull AwesomeFragment fragment, @NonNull PresentAnimation animation) { if (fragmentManager.isDestroyed()) { return; } FragmentTransaction transaction = fragmentManager.beginTransaction(); transaction.setReorderingAllowed(true); transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); AwesomeFragment topFragment = (AwesomeFragment) fragmentManager.findFragmentById(containerId); if (topFragment != null && topFragment.isAdded()) { topFragment.setAnimation(animation); transaction.setMaxLifecycle(topFragment, Lifecycle.State.STARTED); transaction.hide(topFragment); } fragment.setAnimation(animation); transaction.add(containerId, fragment, fragment.getSceneId()); transaction.addToBackStack(fragment.getSceneId()); transaction.commit(); executePendingTransactionsSafe(fragmentManager); }
Example 7
Source File: TabBarFragment.java From AndroidNavigation with MIT License | 6 votes |
private void setChildFragmentsInternal(List<AwesomeFragment> fragments) { FragmentManager fragmentManager = getChildFragmentManager(); FragmentTransaction transaction = fragmentManager.beginTransaction(); for (int i = 0, size = fragments.size(); i < size; i++) { AwesomeFragment fragment = fragments.get(i); fragmentTags.add(fragment.getSceneId()); transaction.add(R.id.tabs_content, fragment, fragment.getSceneId()); if (i == selectedIndex) { transaction.setMaxLifecycle(fragment, Lifecycle.State.RESUMED); transaction.setPrimaryNavigationFragment(fragment); } else { transaction.setMaxLifecycle(fragment, Lifecycle.State.STARTED); transaction.hide(fragment); } } transaction.commit(); FragmentHelper.executePendingTransactionsSafe(fragmentManager); }
Example 8
Source File: AbsSearchBarActivity.java From call_manage with MIT License | 6 votes |
/** * Toggles the search bar according to it's current state */ public void toggleSearchBar(boolean isShow) { FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.setCustomAnimations(R.anim.slide_up, R.anim.slide_down); if (isShow) { mToggled = true; mSearchBarContainer.setVisibility(View.VISIBLE); ft.show(mSearchBarFragment); mSearchBarFragment.setFocus(); Utilities.toggleKeyboard(this, mSearchBarFragment.mSearchInput, true); } else { mToggled = false; mSearchBarContainer.setVisibility(View.GONE); ft.hide(mSearchBarFragment); Utilities.toggleKeyboard(this, mSearchBarFragment.mSearchInput, false); } ft.commit(); }
Example 9
Source File: MainActivity.java From WanAndroid with Apache License 2.0 | 5 votes |
/** * 装载Fragments */ private void loadMultipleFragment(int containerId, int showFragment, Fragment... fragments){ FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); for(int i = 0; i < fragments.length; i++){ Fragment fragment = fragments[i]; transaction.add(containerId, fragment, fragment.getClass().getName()); if(i != showFragment){ transaction.hide(fragment); } } transaction.commitAllowingStateLoss(); }
Example 10
Source File: CommCareWiFiDirectActivity.java From commcare-android with Apache License 2.0 | 5 votes |
private void beSubmitter() { unzipFilesHelper(); myStatusText.setText(localize("wifi.direct.enter.submit.mode")); WiFiDirectManagementFragment wifiFragment = (WiFiDirectManagementFragment)getSupportFragmentManager() .findFragmentById(R.id.wifi_manager_fragment); DeviceListFragment fragmentList = (DeviceListFragment)getSupportFragmentManager() .findFragmentById(R.id.frag_list); DeviceDetailFragment fragmentDetails = (DeviceDetailFragment)getSupportFragmentManager() .findFragmentById(R.id.frag_detail); FileServerFragment fsFragment = (FileServerFragment)getSupportFragmentManager() .findFragmentById(R.id.file_server_fragment); FragmentTransaction tr = getSupportFragmentManager().beginTransaction(); tr.hide(fsFragment); tr.hide(wifiFragment); tr.hide(fragmentList); tr.hide(fragmentDetails); tr.commit(); wifiFragment.setIsHost(false); wifiFragment.resetConnectionGroup(); Logger.log(TAG, "Device designated as submitter"); mState = wdState.submit; changeState(); }
Example 11
Source File: NavigationFragment.java From AndroidNavigation with MIT License | 5 votes |
private void redirectToFragmentInternal(AwesomeFragment fragment, AwesomeFragment target, boolean animated) { FragmentManager fragmentManager = getChildFragmentManager(); AwesomeFragment topFragment = getTopFragment(); if (topFragment == null) { return; } if (target == null) { target = topFragment; } AwesomeFragment aheadFragment = FragmentHelper.getAheadFragment(fragmentManager, target); topFragment.setAnimation(animated ? PresentAnimation.Redirect : PresentAnimation.Fade); if (aheadFragment != null && aheadFragment.isAdded()) { aheadFragment.setAnimation(animated ? PresentAnimation.Redirect : PresentAnimation.Fade); } fragmentManager.beginTransaction().setMaxLifecycle(topFragment, Lifecycle.State.STARTED).commit(); fragmentManager.popBackStack(target.getSceneId(), FragmentManager.POP_BACK_STACK_INCLUSIVE); FragmentTransaction transaction = fragmentManager.beginTransaction(); transaction.setReorderingAllowed(true); transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); if (aheadFragment != null && aheadFragment.isAdded()) { transaction.hide(aheadFragment); transaction.setMaxLifecycle(aheadFragment, Lifecycle.State.STARTED); } fragment.setAnimation(animated ? PresentAnimation.Push : PresentAnimation.None); transaction.add(R.id.navigation_content, fragment, fragment.getSceneId()); transaction.addToBackStack(fragment.getSceneId()); transaction.commit(); FragmentHelper.executePendingTransactionsSafe(fragmentManager); }
Example 12
Source File: WaypointV2ActionDialog.java From Android-GSDemo-Gaode-Map with MIT License | 5 votes |
private void hideTriggerFragment() { if (currentTriggerFragment == null) { return; } FragmentTransaction transaction = getChildFragmentManager().beginTransaction(); transaction.hide(currentTriggerFragment); transaction.commit(); }
Example 13
Source File: PreferenceActivity.java From AndroidPreferenceActivity with Apache License 2.0 | 5 votes |
/** * Shows a specific preference fragment. * * @param navigationPreference * The navigation preference, the fragment, which should be shown, is associated with, * as an instance of the class {@link NavigationPreference}. The navigation preference * may not be null * @param fragment * The fragment, which should be shown, as an instance of the class Fragment. The * fragment may not be null */ private void showPreferenceFragment(@NonNull final NavigationPreference navigationPreference, @NonNull final Fragment fragment) { fragment.setRetainInstance(true); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); if (!isSplitScreen()) { transaction.hide(navigationFragment); if (preferenceFragment != null) { transaction.remove(preferenceFragment); notifyOnPreferenceFragmentHidden(preferenceFragment); } transaction.add(R.id.navigation_fragment_container, fragment, PREFERENCE_FRAGMENT_TAG); } else { if (preferenceFragment != null) { notifyOnPreferenceFragmentHidden(preferenceFragment); } transaction .replace(R.id.preference_fragment_container, fragment, PREFERENCE_FRAGMENT_TAG); } transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); transaction.commit(); this.preferenceFragment = fragment; showToolbarNavigationIcon(); adaptBreadCrumbVisibility(selectedPreferenceFragmentArguments); notifyOnPreferenceFragmentShown(navigationPreference, fragment); }
Example 14
Source File: PostItemListActivity.java From mimi-reader with Apache License 2.0 | 5 votes |
@Override public void onBoardItemClick(ChanBoard board, boolean saveBackStack) { final Bundle arguments = new Bundle(); arguments.putString(Extras.EXTRAS_BOARD_NAME, board.getName()); arguments.putString(Extras.EXTRAS_BOARD_TITLE, board.getTitle()); arguments.putBoolean(Extras.EXTRAS_TWOPANE, mTwoPane); PostItemsListFragment fragment = new PostItemsListFragment(); fragment.setArguments(arguments); // fragment.setBoards(boards); final FragmentManager fm = getSupportFragmentManager(); final FragmentTransaction ft = fm.beginTransaction(); final Fragment catalogItemsFragment = fm.findFragmentByTag(TAG_POST_LIST); if (catalogItemsFragment != null) { ft.remove(catalogItemsFragment); } if (currentFragment != null) { ft.hide(currentFragment); } ft.add(R.id.postitem_list, fragment, TAG_POST_LIST); if (saveBackStack) { ft.addToBackStack(null); } ft.commit(); currentFragment = fragment; setFabVisibility(currentFragment.showFab()); }
Example 15
Source File: NoteTakingActivity.java From science-journal with Apache License 2.0 | 5 votes |
private void hideAllFragmentsInToolPane() { FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction ft = fragmentManager.beginTransaction(); for (Fragment fragment : fragmentManager.getFragments()) { if (!fragment.equals(defaultFragment)) { ft.hide(fragment); } } ft.commit(); }
Example 16
Source File: MenuManager.java From cv4j with Apache License 2.0 | 5 votes |
private void hide(MenuType type) { Fragment fragment = (Fragment) fragmentManager.findFragmentByTag(type.getTitle()); if (fragment != null) { if (type.isRemoved()) { fragmentManager.beginTransaction().remove(fragment).commit(); } else { FragmentTransaction ft = fragmentManager.beginTransaction(); // ft.addToBackStack(type.getTitle()); ft.hide(fragment); ft.commit(); } } }
Example 17
Source File: SubsonicFragmentActivity.java From Audinaut with GNU General Public License v3.0 | 5 votes |
@Override public void onRestoreInstanceState(Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); String id = savedInstanceState.getString(Constants.MAIN_NOW_PLAYING); FragmentManager fm = getSupportFragmentManager(); nowPlayingFragment = (NowPlayingFragment) fm.findFragmentByTag(id); String secondaryId = savedInstanceState.getString(Constants.MAIN_NOW_PLAYING_SECONDARY); if (secondaryId != null) { secondaryFragment = (SubsonicFragment) fm.findFragmentByTag(secondaryId); nowPlayingFragment.setPrimaryFragment(false); secondaryFragment.setPrimaryFragment(true); FragmentTransaction trans = getSupportFragmentManager().beginTransaction(); trans.hide(nowPlayingFragment); trans.commit(); } if (drawerToggle != null && backStack.size() > 0) { drawerToggle.setDrawerIndicatorEnabled(false); } if (savedInstanceState.getInt(Constants.MAIN_SLIDE_PANEL_STATE, -1) == SlidingUpPanelLayout.PanelState.EXPANDED.hashCode()) { panelSlideListener.onPanelStateChanged(null, null, PanelState.EXPANDED); } }
Example 18
Source File: MyActivity.java From googleads-ima-android with Apache License 2.0 | 5 votes |
private void orientAppUi() { int orientation = getResources().getConfiguration().orientation; boolean isLandscape = (orientation == Configuration.ORIENTATION_LANDSCAPE); // Hide the non-video content when in landscape so the video is as large as possible. FragmentManager fragmentManager = getSupportFragmentManager(); VideoFragment videoFragment = (VideoFragment) fragmentManager.findFragmentByTag(VIDEO_EXAMPLE_FRAGMENT_TAG); Fragment videoListFragment = fragmentManager.findFragmentByTag(VIDEO_PLAYLIST_FRAGMENT_TAG); if (videoFragment != null) { // If the video playlist is onscreen (tablets) then hide that fragment. if (videoListFragment != null) { FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); if (isLandscape) { fragmentTransaction.hide(videoListFragment); } else { fragmentTransaction.show(videoListFragment); } fragmentTransaction.commit(); } videoFragment.makeFullscreen(isLandscape); if (isLandscape) { hideStatusBar(); } else { showStatusBar(); } } else { // If returning to the list from a fullscreen video, check if the video // list fragment exists and is hidden. If so, show it. if (videoListFragment != null && videoListFragment.isHidden()) { fragmentManager.beginTransaction().show(videoListFragment).commit(); showStatusBar(); } } }
Example 19
Source File: MainActivity.java From ProjectX with Apache License 2.0 | 5 votes |
private void setFragment(String tag) { final String oldTag = mCurrent; mCurrent = tag; final FragmentManager manager = getSupportFragmentManager(); final FragmentTransaction transaction = manager.beginTransaction(); if (!TextUtils.isEmpty(oldTag)) { final Fragment old = manager.findFragmentByTag(oldTag); if (old != null && old.isVisible()) { transaction.hide(old); } } Fragment target = manager.findFragmentByTag(tag); if (target != null && target.isVisible()) return; if (target == null) { switch (tag) { default: case TAG_WIDGETS: target = WidgetsFragment.newInstance(); break; case TAG_DRAWABLES: target = DrawablesFragment.newInstance(); break; case TAG_OTHERS: target = OthersFragment.newInstance(); break; case TAG_DEVELOP: target = DevelopFragment.newInstance(); break; } transaction.add(mVContent.getId(), target, tag); } transaction.show(target); transaction.commit(); }
Example 20
Source File: SubsonicActivity.java From Audinaut with GNU General Public License v3.0 | 4 votes |
@Override public void onRestoreInstanceState(Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); int size = savedInstanceState.getInt(Constants.MAIN_BACK_STACK_SIZE); String[] ids = savedInstanceState.getStringArray(Constants.MAIN_BACK_STACK); FragmentManager fm = getSupportFragmentManager(); currentFragment = (SubsonicFragment) fm.findFragmentByTag(ids[0]); currentFragment.setPrimaryFragment(true); currentFragment.setSupportTag(ids[0]); supportInvalidateOptionsMenu(); FragmentTransaction trans = getSupportFragmentManager().beginTransaction(); for (int i = 1; i < size; i++) { SubsonicFragment frag = (SubsonicFragment) fm.findFragmentByTag(ids[i]); frag.setSupportTag(ids[i]); if (secondaryContainer != null) { frag.setPrimaryFragment(false, true); } trans.hide(frag); backStack.add(frag); } trans.commit(); // Current fragment is hidden in secondaryContainer if (secondaryContainer == null && !currentFragment.isVisible()) { trans = getSupportFragmentManager().beginTransaction(); trans.remove(currentFragment); trans.commit(); getSupportFragmentManager().executePendingTransactions(); trans = getSupportFragmentManager().beginTransaction(); trans.add(R.id.fragment_container, currentFragment, ids[0]); trans.commit(); } // Current fragment needs to be moved over to secondaryContainer else if (secondaryContainer != null && secondaryContainer.findViewById(currentFragment.getRootId()) == null && backStack.size() > 0) { trans = getSupportFragmentManager().beginTransaction(); trans.remove(currentFragment); trans.show(backStack.get(backStack.size() - 1)); trans.commit(); getSupportFragmentManager().executePendingTransactions(); trans = getSupportFragmentManager().beginTransaction(); trans.add(R.id.fragment_second_container, currentFragment, ids[0]); trans.commit(); secondaryContainer.setVisibility(View.VISIBLE); } lastSelectedPosition = savedInstanceState.getInt(Constants.FRAGMENT_POSITION); if (lastSelectedPosition != 0) { MenuItem item = drawerList.getMenu().findItem(lastSelectedPosition); if (item != null) { item.setChecked(true); } } recreateSpinner(); }