Java Code Examples for androidx.fragment.app.FragmentTransaction#show()
The following examples show how to use
androidx.fragment.app.FragmentTransaction#show() .
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: 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 3
Source File: BaseFragment.java From HaoReader with GNU General Public License v3.0 | 6 votes |
@Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (savedInstanceState != null && getFragmentManager() != null) { isSupportHidden = savedInstanceState.getBoolean(STATE_SAVE_IS_HIDDEN); FragmentTransaction ft = getFragmentManager().beginTransaction(); if (isSupportHidden) { ft.hide(this); } else { ft.show(this); } ft.commit(); } else { isSupportHidden = isHidden(); } }
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: FragmentChangeManager.java From UIWidget with Apache License 2.0 | 6 votes |
/** * 界面切换控制 */ public void setFragments(int index) { for (int i = 0; i < mFragments.size(); i++) { FragmentTransaction ft = mFragmentManager.beginTransaction(); Fragment fragment = mFragments.get(i); if (i == index) { ft.show(fragment); } else { ft.hide(fragment); } //解决当前页面设置上一页面currentTab Fragment不同时切换问题 //一定几率报 IllegalStateException: Can not perform this action after onSaveInstanceState 异常 ft.commitAllowingStateLoss(); } mCurrentTab = index; }
Example 6
Source File: SubsonicFragmentActivity.java From Audinaut with GNU General Public License v3.0 | 6 votes |
@Override public void removeCurrent() { if (isNowPlayingOpen() && secondaryFragment != null) { FragmentTransaction trans = getSupportFragmentManager().beginTransaction(); trans.setCustomAnimations(R.anim.enter_from_left, R.anim.exit_to_right, R.anim.enter_from_right, R.anim.exit_to_left); trans.remove(secondaryFragment); trans.show(nowPlayingFragment); trans.commit(); secondaryFragment = null; nowPlayingFragment.setPrimaryFragment(true); supportInvalidateOptionsMenu(); } else { super.removeCurrent(); } }
Example 7
Source File: WaypointV2ActionDialog.java From Android-GSDemo-Gaode-Map with MIT License | 6 votes |
private void showFragment(Fragment fragment, @IdRes int id) { if (fragment == null || fragment.isResumed()) { return; } FragmentTransaction transaction = getChildFragmentManager().beginTransaction(); if (fragment.isAdded()) { if (fragment instanceof BaseTriggerFragment && currentTriggerFragment != null) { transaction.hide(currentTriggerFragment); } else if (fragment instanceof IActuatorCallback && currentActuatorFragment != null) { transaction.hide(currentActuatorFragment); } transaction.show(fragment); } else { transaction.replace(id, fragment); } transaction.commit(); }
Example 8
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 9
Source File: PreferenceActivity.java From AndroidPreferenceActivity with Apache License 2.0 | 6 votes |
/** * Removes the currently preference fragment, regardless of whether the split screen layout is * used, or not. */ private void removePreferenceFragmentUnconditionally() { if (isPreferenceFragmentShown()) { resetTitle(); hideToolbarNavigationIcon(); adaptBreadCrumbVisibility(); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); transaction.remove(preferenceFragment); if (!isSplitScreen()) { transaction.show(navigationFragment); } transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE); transaction.commit(); notifyOnPreferenceFragmentHidden(preferenceFragment); preferenceFragment = null; } }
Example 10
Source File: CommCareWiFiDirectActivity.java From commcare-android with Apache License 2.0 | 5 votes |
private void beReceiver() { myStatusText.setText(localize("wifi.direct.enter.receive.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.show(wifiFragment); tr.show(fragmentList); tr.show(fragmentDetails); tr.show(fsFragment); tr.commit(); wifiFragment.setIsHost(true); wifiFragment.resetConnectionGroup(); Logger.log(TAG, "Device designated as receiver"); resetData(); hostGroup(); mState = wdState.receive; changeState(); }
Example 11
Source File: CommCareWiFiDirectActivity.java From commcare-android with Apache License 2.0 | 5 votes |
private void beSender() { myStatusText.setText(localize("wifi.direct.enter.send.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.show(wifiFragment); tr.show(fragmentList); tr.show(fragmentDetails); tr.hide(fsFragment); tr.commit(); wifiFragment.setIsHost(false); wifiFragment.resetConnectionGroup(); Logger.log(TAG, "Device designated as sender"); resetData(); mState = wdState.send; changeState(); }
Example 12
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 13
Source File: MainActivity.java From geopackage-mapcache-android with MIT License | 5 votes |
/** * Set up the map fragment */ private void createMainFragment(){ FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction transaction = fragmentManager.beginTransaction(); transaction.show(mapFragment); title = getString(R.string.title_map); transaction.commit(); }
Example 14
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 15
Source File: FragmentTabAdapter.java From ZhiHuIndex with Apache License 2.0 | 5 votes |
private void showTab(int idx) { for (int i = 0; i < fragments.size(); i++) { Fragment fragment = fragments.get(i); FragmentTransaction ft = obtainFragmentTransaction(idx); if (idx == i) { ft.show(fragment); } else { ft.hide(fragment); } ft.commit(); } currentTab = idx; }
Example 16
Source File: FragmentLifecycleActivity.java From AndroidAll with Apache License 2.0 | 5 votes |
public void showFragment(@NonNull Fragment fragment) { //相当于new一个实例FragmentTransaction FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); if (fragment.isAdded()) { ft.show(fragment); } else { //把该ft加入到栈中进行管理 ft.addToBackStack(fragment.getClass().getSimpleName()); ft.add(R.id.container, fragment); } ft.commitAllowingStateLoss(); Log.e("Lifecycle", "getBackStackEntryCount: " + getSupportFragmentManager().getBackStackEntryCount()); }
Example 17
Source File: MainActivity.java From AndroidAll with Apache License 2.0 | 5 votes |
private void showFragment(@NonNull FragmentManager fragmentManager, @NonNull Fragment fragment, int frameId) { //Log.e("Lifecycle", "MainActivity fragment.isAdded() : " + fragment.isAdded() + ", " + fragment); FragmentTransaction ft = fragmentManager.beginTransaction(); if (fragment.isAdded()) { ft.show(fragment); } else { ft.add(frameId, fragment); } ft.commitAllowingStateLoss(); }
Example 18
Source File: TabBarFragment.java From AndroidNavigation with MIT License | 5 votes |
private void setSelectedIndexInternal(int index) { if (tabBarProvider != null) { tabBarProvider.setSelectedIndex(index); } if (selectedIndex == index) { return; } selectedIndex = index; FragmentManager fragmentManager = getChildFragmentManager(); AwesomeFragment previous = (AwesomeFragment) fragmentManager.getPrimaryNavigationFragment(); AwesomeFragment current = fragments.get(index); FragmentTransaction transaction = fragmentManager.beginTransaction(); transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); transaction.setPrimaryNavigationFragment(current); if (previous != null && previous.isAdded()) { setPresentAnimation(current, previous); transaction.setMaxLifecycle(previous, Lifecycle.State.STARTED); transaction.hide(previous); } transaction.setMaxLifecycle(current, Lifecycle.State.RESUMED); transaction.show(current); transaction.commit(); FragmentHelper.executePendingTransactionsSafe(fragmentManager); if (tabBar != null) { NavigationFragment navigationFragment = current.getNavigationFragment(); if (navigationFragment != null && navigationFragment.shouldHideTabBarWhenPushed()) { if (navigationFragment.getChildFragmentCountAtBackStack() <= 1) { showTabBar(); } else { hideTabBar(); } } else { showTabBar(); } } }
Example 19
Source File: MessageActivity.java From tindroid with Apache License 2.0 | 4 votes |
void showFragment(String tag, Bundle args, boolean addToBackstack) { if (isFinishing() || isDestroyed()) { return; } FragmentManager fm = getSupportFragmentManager(); Fragment fragment = fm.findFragmentByTag(tag); if (fragment == null) { switch (tag) { case FRAGMENT_MESSAGES: fragment = new MessagesFragment(); break; case FRAGMENT_INFO: fragment = new TopicInfoFragment(); break; case FRAGMENT_PERMISSIONS: fragment = new TopicPermissionsFragment(); break; case FRAGMENT_EDIT_MEMBERS: fragment = new EditMembersFragment(); break; case FRAGMENT_VIEW_IMAGE: fragment = new ImageViewFragment(); break; case FRAGMENT_FILE_PREVIEW: fragment = new FilePreviewFragment(); break; case FRAGMENT_INVALID: fragment = new InvalidTopicFragment(); break; } } else if (args == null) { // Retain old arguments. args = fragment.getArguments(); } if (fragment == null) { throw new NullPointerException(); } args = args != null ? args : new Bundle(); args.putString("topic", mTopicName); args.putString(MessagesFragment.MESSAGE_TO_SEND, mMessageText); if (fragment.getArguments() != null) { fragment.getArguments().putAll(args); } else { fragment.setArguments(args); } FragmentTransaction trx = fm.beginTransaction(); if (!fragment.isAdded()) { trx = trx.replace(R.id.contentFragment, fragment, tag) .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); } else if (!fragment.isVisible()) { trx = trx.show(fragment); } else { addToBackstack = false; } if (FRAGMENT_MESSAGES.equals(tag)) { trx.setPrimaryNavigationFragment(fragment); } if (addToBackstack) { trx.addToBackStack(tag); } if (!trx.isEmpty()) { trx.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(); }