public void setCurrentItem(int itemId) { String name = makeFragmentName(containerId, itemId); Fragment fragment = manager.findFragmentByTag(name); FragmentTransaction fragmentTransaction = manager.beginTransaction(); if (fragment != null) { fragmentTransaction.attach(fragment); if (fragment.isHidden()) { fragmentTransaction.show(fragment); } } else { fragment = getItem(itemId); fragmentTransaction.add(containerId, fragment, name); } if (fragment != current && current != null) { fragmentTransaction.hide(current); } current = fragment; fragmentTransaction.commit(); }
/** * Show fragments listing books. * @param addToBackStack add to back stack or not */ public static void displayBooks(FragmentManager fragmentManager, boolean addToBackStack) { if (isFragmentDisplayed(fragmentManager, BooksFragment.FRAGMENT_TAG) != null) { return; } Fragment fragment = BooksFragment.getInstance(); FragmentTransaction t = fragmentManager .beginTransaction() .setTransition(FRAGMENT_TRANSITION) .replace(R.id.single_pane_container, fragment, BooksFragment.FRAGMENT_TAG); if (addToBackStack) { t.addToBackStack(null); } t.commit(); }
/**选择并显示fragment * @param position */ public void selectFragment(int position) { if (currentPosition == position) { if (needReload == false && fragments[position] != null && fragments[position].isVisible()) { Log.w(TAG, "selectFragment currentPosition == position" + " >> fragments[position] != null && fragments[position].isVisible()" + " >> return; "); return; } } if (needReload || fragments[position] == null) { fragments[position] = getFragment(position); } //全局的fragmentTransaction因为already committed 崩溃 FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.hide(fragments[currentPosition]); if (fragments[position].isAdded() == false) { fragmentTransaction.add(R.id.flBaseTabFragmentContainer, fragments[position]); } fragmentTransaction.show(fragments[position]).commit(); this.currentPosition = position; }
private void showFragmentV11(@IdRes int containerId, String showTag, String hideTag) { android.app.FragmentManager fragmentManager = getFragmentManager(); android.app.FragmentTransaction transaction = fragmentManager.beginTransaction(); AnimationHelper.setUpRotate3dAnimator(transaction); android.app.Fragment showFragment = fragmentManager.findFragmentByTag(showTag); if (showFragment == null) { showFragment = SampleFragmentV11.newInstance("SampleFragmentV11\n" + showTag); transaction.add(containerId, showFragment, showTag); } else { transaction.show(showFragment); } android.app.Fragment hideFragment = fragmentManager.findFragmentByTag(hideTag); if (hideFragment != null) { transaction.hide(hideFragment); } transaction.commit(); }
private void initCitySelect(){ citySelectFragment = CitySelectFragment.newInstance(new CitySelectFragment.OnSelectCity() { @Override public void onSelectCity(String disCode) { districtCode = disCode; pullToRefreshLayout.showView(ViewStatus.LOADING_STATUS); if(list.isEmpty()){ pullToRefreshLayout.showView(ViewStatus.LOADING_STATUS); } getP().refresh(searchText,disCode); } }); FragmentManager fm = getSupportFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); ft.add(R.id.city_fragment_container, citySelectFragment); ft.commit(); }
/** * onTabClicked * * @param view */ public void onTabClicked(View view) { switch (view.getId()) { case R.id.btn_conversation: index = 0; break; case R.id.btn_address_list: index = 1; break; case R.id.btn_setting: index = 2; break; } if (currentTabIndex != index) { FragmentTransaction trx = getSupportFragmentManager().beginTransaction(); trx.hide(fragments[currentTabIndex]); if (!fragments[index].isAdded()) { trx.add(R.id.fragment_container, fragments[index]); } trx.show(fragments[index]).commit(); } mTabs[currentTabIndex].setSelected(false); // set current tab as selected. mTabs[index].setSelected(true); currentTabIndex = index; }
/** * Trick: * Manually recreate fragment when corresponding data changed */ public void hackRecreateFragment(int position) { final FragmentTransaction transaction = mFragmentManager.beginTransaction(); final String tag = makeFragmentTag(mContainerId, getItemId(position)); final Fragment oldFrg = mFragmentManager.findFragmentByTag(tag); if (oldFrg != null) { final Fragment newFrg = getItem(position); transaction.remove(oldFrg); transaction.add(mContainerId, newFrg, tag); if (oldFrg != mCurrentPrimaryItem) { newFrg.setMenuVisibility(false); newFrg.setUserVisibleHint(false); } else { newFrg.setMenuVisibility(true); newFrg.setUserVisibleHint(true); } } transaction.commitNowAllowingStateLoss(); }
/** * 添加下一个Fragment,隐藏当前的Fragment * @param frameLayoutId * @param fragment */ protected void addFragment(int frameLayoutId,Fragment fragment) { if (fragment != null) { FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); if (fragment.isAdded()) { if (mFragment != null) { transaction.hide(mFragment).show(fragment); } else { transaction.show(fragment); } } else { if (mFragment != null) { transaction.hide(mFragment).add(frameLayoutId, fragment); } else { transaction.add(frameLayoutId, fragment); } } mFragment = fragment; transaction.commit(); } }
private void switchFragment(NavButton oldNavButton, NavButton selectNav) { FragmentTransaction transaction = mFragmentManager.beginTransaction(); if (oldNavButton != null) { if (oldNavButton.getFragment() != null) { transaction.detach(oldNavButton.getFragment()); } } if (selectNav != null) { if (selectNav.getFragment() != null) { transaction.attach(selectNav.getFragment()); } else { // Fragment.instantiate工具方法,再也不用自己newInstance(). Fragment fragment = Fragment.instantiate(mContext, selectNav.getClx().getName(), null); transaction.add(mContainerId, fragment, selectNav.getNavBtnTag()); selectNav.setFragment(fragment); } } transaction.commit(); }
/** * Toggle API drawer */ public void showAPIDrawer(boolean b) { FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_left, R.anim.slide_out_left, R.anim.slide_out_left); if (b) { webviewFragment = new APIWebviewFragment(); Bundle bundle = new Bundle(); bundle.putString("url", "http://localhost:8585/reference.html"); webviewFragment.setArguments(bundle); ft.add(R.id.fragmentWebview, webviewFragment).addToBackStack(null); editorFragment.getView().animate().translationX(-50).setDuration(500).start(); } else { editorFragment.getView().animate().translationX(0).setDuration(500).start(); ft.remove(webviewFragment); } ft.commit(); }
protected void showFragment(int containerId, Fragment from, Fragment to, String tag) { FragmentManager supportFragmentManager = getSupportFragmentManager(); FragmentTransaction transaction = supportFragmentManager.beginTransaction(); if (!to.isAdded()) { // 先判断是否被add过 if (tag != null) { transaction.hide(from).add(containerId, to, tag); } else { transaction.hide(from).add(containerId, to); } // 隐藏当前的fragment,add下一个到Activity中 } else { transaction.hide(from).show(to); // 隐藏当前的fragment,显示下一个 } transaction.commit(); }
@SuppressWarnings("RestrictedApi") private void clearOldFragment() { FragmentTransaction transaction = mFragmentManager.beginTransaction(); List<Fragment> fragments = mFragmentManager.getFragments(); if (transaction == null || fragments == null || fragments.size() == 0) return; boolean doCommit = false; for (Fragment fragment : fragments) { if (fragment != this && fragment != null) { transaction.remove(fragment); doCommit = true; } } if (doCommit) transaction.commitNow(); }
private void restoreValuesInit(List<RecyclerViewItem> items) { ButtonView2 bv = new ButtonView2(); bv.setSummary(getString(R.string.restore_summary)); bv.setButtonText(getString(R.string.restore_button)); bv.setOnItemClickListener(new ButtonView2.OnItemClickListener(){ @Override public void onClick(RecyclerViewItem item) { Calibration.restoreCalibrationStockValues(getActivity()); FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.replace(R.id.content_frame, new ScreenFragment()).commit(); } }); items.add(bv); }
private void switchFrag(BaseFragment fragment){ setActionBarTitleAgain(fragment.getTitle()); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); if (!fragments.get(fragment)){ transaction.add(R.id.main_content, fragment); fragments.put(fragment, true); } for (BaseFragment baseFragment : fragments.keySet()) { if (baseFragment != null) transaction.hide(baseFragment); } transaction.show(fragment); transaction.commit(); View.OnClickListener action_end = fragment.getMenuAction_end(); if (action_end != null){ initActionBar(ACTIONBAR_TYPE_CUSTOM, R.drawable.umi_ic_menu_white, R.drawable.ic_filter_list_white_24dp); actionBarEndAction(action_end); }else { initActionBar(ACTIONBAR_TYPE_CUSTOM, R.drawable.umi_ic_menu_white, null); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); getWindow().setStatusBarColor(Color.TRANSPARENT); } setContentView(R.layout.activity_main); ButterKnife.bind(this); setSupportActionBar(mToolbar); ControlPanel.get().attachView(mLayoutPanel); getSupportFragmentManager().beginTransaction() .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE) .replace(R.id.fragment_container, new HomeFragment()) .commit(); getSupportFragmentManager().addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() { @Override public void onBackStackChanged() { if (getSupportFragmentManager().getBackStackEntryCount() == 0) { ControlPanel.get().expand(mLayoutPanel); } } }); }
public void addTab(TabSpec tabSpec, Class<?> clss, Bundle args) { tabSpec.setContent(new DummyTabFactory(mContext)); String tag = tabSpec.getTag(); TabInfo info = new TabInfo(tag, clss, args); if (mAttached) { // If we are already attached to the window, then check to make // sure this tab's fragment is inactive if it exists. This shouldn't // normally happen. info.fragment = mFragmentManager.findFragmentByTag(tag); if (info.fragment != null && !info.fragment.isDetached()) { FragmentTransaction ft = mFragmentManager.beginTransaction(); // ft.detach(info.fragment); ft.hide(info.fragment); ft.commit(); } } mTabs.add(info); addTab(tabSpec); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //加载某一个类 loadDexClass(); //加载一个fragment Fragment fragment = loadFragment() ; if ( fragment != null ){ FragmentManager fragmentManager = getSupportFragmentManager() ; FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction() ; fragmentTransaction.add( R.id.fragmentrle ,fragment ) ; fragmentTransaction.commit() ; } }
void btnclick(View view) { //Fragment fragment=null; switch (view.getId()){ case R.id.btn_learn: fragment=new On_going_Courses_Fragment(); break; case R.id.btn_explore: // getNews(); fragment=new NewsFragment(); break; case R.id.btn_profile: fragment=new profile_fragment(); break; } FragmentManager fragmentManager=getSupportFragmentManager(); FragmentTransaction fragmentTransaction=fragmentManager.beginTransaction(); fragmentTransaction.replace(R.id.homeFrame_PlaceHolder,fragment); fragmentTransaction.commit(); }
private void displayObservAddEdit(DSObject dsObjectSelected, int viewID) { ObservationAddFragment observationFragment = new ObservationAddFragment(); // specify dsObject as an argument to the addedit Fragment Bundle arguments = new Bundle(); arguments.putParcelable("dsObjectArrayListItem", dsObjectSelected); observationFragment.setArguments(arguments); // use a FragmentTransaction to display the addedit Fragment FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); transaction.replace(viewID, observationFragment); transaction.addToBackStack(null); transaction.commit(); // causes addedit Fragment to display }
public void init() { mFriendFragment = new HelpMeFriendFragment(mApplication, this, this); mHelperFragment = new MeHelpFriendFragment(mApplication, this, this); FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.replace(R.id.myfriend_layout_content, mFriendFragment).commit(); currentFragment = false; //从数据库中获取存有四种好友状态的list // DBManage.context = FriendActivity.this; // mFriendList1 = FriendDB.newInstance(FriendActivity.this).getFriendByCount(mFriendCount1++,FriendState.TRADING,HelpRelation.HELP_ME); mFriendList1 = DBManage.getFriendByCount(mFriendCount1++,FriendState.TRADING,HelpRelation.HELP_ME); mFriendList2 = DBManage.getFriendByCount(mFriendCount2++,FriendState.SUCCESS,HelpRelation.HELP_ME); mHelperList1 = DBManage.getFriendByCount(mHelperCount1++,FriendState.TRADING,HelpRelation.ME_HELP); mHelperList2 = DBManage.getFriendByCount(mHelperCount2++,FriendState.SUCCESS,HelpRelation.ME_HELP); mFriendFragment.setHiBangUserList(mFriendList1, mFriendList2); mHelperFragment.setHiBangUserList(mHelperList1, mHelperList2); }
/** * 替换fragement 并添加动画 */ public void replaceFragment(@IdRes int id_content, @AnimRes int anim_in, @AnimRes int anim_out, Fragment fragment) { FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); // transaction.setCustomAnimations(anim_in, anim_out); transaction.replace(id_content, fragment); transaction.commit(); }
private void processRestoreInstanceState(Bundle savedInstanceState) { if (savedInstanceState != null) { FragmentTransaction ft = mFragment.getFragmentManager().beginTransaction(); if (mIsHidden) { ft.hide(mFragment); } else { ft.show(mFragment); } ft.commitAllowingStateLoss(); } }
public static void addFragmentToActivity(@Nullable FragmentManager manager , @Nullable Fragment fragment, int containerId) { checkNotNull(manager); checkNotNull(fragment); FragmentTransaction transaction = manager.beginTransaction(); transaction.replace(containerId, fragment); transaction.commit(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Fragment fragment = new WalletFragment(); FragmentTransaction ftrans = getSupportFragmentManager().beginTransaction(); ftrans.replace(R.id.fragment_framelayout, fragment); ftrans.addToBackStack(null); ftrans.commit(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_vehicle_tabbed_detail); setSupportActionBar((Toolbar) findViewById(R.id.detail_toolbar)); getSupportActionBar().setDisplayHomeAsUpEnabled(true); fragmentManager = getSupportFragmentManager(); ((BottomNavigationView) findViewById(R.id.vehicle_detail_navigation)).setOnNavigationItemSelectedListener(this); if (savedInstanceState == null) { Intent intent = getIntent(); long vehicleId = intent.getLongExtra(VehicleListFragment.EXTRA_ADDED_VEHICLE_ID, 0); vehicle = VehicleService.getVehicleById(vehicleId, this); fragment = new FillUpsListFragment(); Bundle bundle = new Bundle(); bundle.putParcelable(VEHICLE_TO_FRAGMENT, vehicle); fragment.setArguments(bundle); FragmentTransaction transaction = fragmentManager.beginTransaction(); transaction.replace(R.id.vehicle_detail_frame, fragment).commit(); } else { vehicle = savedInstanceState.getParcelable(VEHICLE_TO_FRAGMENT); } }
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); ArticleFragment fragment = new ArticleFragment(); fragment.setArguments(getIntent().getBundleExtra("param")); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); transaction.replace(android.R.id.content, fragment); transaction.commit(); }
private void setSelectFragment() { FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); transaction.replace(R.id.rl_devices_content, selectFragment); transaction.commit(); try { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); View focusedView = getCurrentFocus(); imm.hideSoftInputFromWindow(focusedView.getWindowToken(), 0); } catch (NullPointerException e){ e.printStackTrace(); } }
private void initFragment(Fragment fragment) { // Add the fragment to the layout FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction transaction = fragmentManager.beginTransaction(); transaction.add(R.id.content_frame, fragment); transaction.commit(); }
public static void dismissDialog(FragmentManager manager) { FragmentTransaction ft = manager.beginTransaction(); Fragment fragment = manager.findFragmentByTag("dialog"); if (fragment != null) { ft.remove(fragment).commit(); } }
/** * Open {@link EditPoiFragment} to add more info o POi * * @param poi {@link ParcelablePOI} to edit */ public void editPoi(ParcelablePOI poi) { //check authentication before editing if (!checkAuthentication()) return; //close PoiListFragment if it is open PoiListFragment poiListFragment = (PoiListFragment) getSupportFragmentManager().findFragmentByTag("PoiListFragment"); if (poiListFragment != null) getSupportFragmentManager() .beginTransaction() .remove(poiListFragment) .commit(); //if MapFragment is open close any routing MapFragment MapFragment = (MapFragment) getSupportFragmentManager().findFragmentByTag("MapFragment"); if (MapFragment != null) { MapFragment.clearMapDisplay(); } Fragment fragment = EditPoiFragment.newInstance(poi); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); transaction.replace(R.id.container, fragment, "EditPoiFragment");// give your fragment container id in first parameter transaction.addToBackStack(null); // if written, this transaction will be added to backstack transaction.commit(); hideNavigation(); }
@Override protected void init() { homeFragment = new HomeFragment(); gameFragment = new GameFragment(); shopFragment = new ShopFragment(); meFragment = new MeFragment(); //各menu与对应的fragment绑定在一起 bmHome.setFragment(homeFragment); bmGame.setFragment(gameFragment); bmShop.setFragment(shopFragment); bmMe.setFragment(meFragment); FragmentManager manager = getSupportFragmentManager(); FragmentTransaction transaction = manager.beginTransaction(); transaction.add(R.id.fragment_containter_main,homeFragment); transaction.add(R.id.fragment_containter_main,gameFragment); transaction.add(R.id.fragment_containter_main,shopFragment); transaction.add(R.id.fragment_containter_main,meFragment); transaction.hide(homeFragment); transaction.hide(gameFragment); transaction.hide(shopFragment); transaction.hide(meFragment); transaction.commit(); bmHome.performClick(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_barcode_fragment_test); FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); BarcodeFragment bf = new BarcodeFragment(); ft.add(R.id.container, bf); ft.commit(); }
@Override public void replaceFragment(BaseFragment baseFragment, boolean isBackStack, int inAnim, int outAnim) { FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction() .setCustomAnimations(inAnim, outAnim) .replace(idContent, baseFragment); if (isBackStack) { fragmentTransaction.addToBackStack(baseFragment.getClass().getName()); } fragmentTransaction.commitAllowingStateLoss(); }
@Override protected void initViews(ViewHolder holder, View root) { Intent intent = getIntent(); int NodeId = intent.getIntExtra(Key_Node_ID, 0); String NodeName = intent.getStringExtra(Key_Node_Name); setTitle(NodeName); NodeTopicListFragment fragment = NodeTopicListFragment.newInstance(NodeId); FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction transaction = fragmentManager.beginTransaction(); transaction.add(R.id.fragment, fragment); transaction.commit(); }
/** * Shows fragment at position and detaches previous fragment if exists. If fragment is found in * fragment manager, it is reattached else added. * * @param position * @return fragment at position */ public Fragment changeFragment(int position) { String tag = makeFragmentName(container.getId(), getItemId(position)); FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction(); /* If fragment manager doesn't have an instance of the fragment, get an instance and add it to the transaction. Else, attach the instance to transaction. */ Fragment fragment = mFragmentManager.findFragmentByTag(tag); if (fragment == null) { fragment = getItem(position); fragmentTransaction.add(container.getId(), fragment, tag); } else { fragmentTransaction.attach(fragment); } // Detach existing primary fragment Fragment curFrag = mFragmentManager.getPrimaryNavigationFragment(); if (curFrag != null) { fragmentTransaction.detach(curFrag); } // Set fragment as primary navigator for child manager back stack to be handled by system fragmentTransaction.setPrimaryNavigationFragment(fragment); fragmentTransaction.setReorderingAllowed(true); fragmentTransaction.commitNowAllowingStateLoss(); return fragment; }
@Override public void viewDetails(int position, long[] callIds) { ListView lv = getListView(); if(mMode != null) { lv.setItemChecked(position, !lv.isItemChecked(position)); mMode.invalidate(); // Don't see details in this case return; } if (mDualPane) { // If we are not currently showing a fragment for the new // position, we need to create and install a new one. CallLogDetailsFragment df = new CallLogDetailsFragment(); Bundle bundle = new Bundle(); bundle.putLongArray(CallLogDetailsFragment.EXTRA_CALL_LOG_IDS, callIds); df.setArguments(bundle); // Execute a transaction, replacing any existing fragment // with this one inside the frame. FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.replace(R.id.details, df, null); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); ft.commit(); getListView().setItemChecked(position, true); } else { Intent it = new Intent(getActivity(), CallLogDetailsActivity.class); it.putExtra(CallLogDetailsFragment.EXTRA_CALL_LOG_IDS, callIds); getActivity().startActivity(it); } }
@Override public void replaceFragmentWithSharedElement(BaseFragment baseFragment, List<View> views) { FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction() .replace(idContent, baseFragment); if (views != null && !views.isEmpty()) { for (View view : views) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { fragmentTransaction.addSharedElement(view, view.getTransitionName()); } } } fragmentTransaction.addToBackStack(baseFragment.getClass().getName()).commitAllowingStateLoss(); }
@Override public void onCheckedChanged(RadioGroup radioGroup, int checkId) { for (int i = 0; i < radioGroup.getChildCount(); i++) { if (radioGroup.getChildAt(i).getId() == checkId) { // 即将要展示的Fragment Fragment target = mFragmentList.get(i); Fragment currentFragment = getCurrentFragment(); currentFragment.onPause(); FragmentTransaction fragmentTransaction = getFragmentTransaction(); if (target.isAdded()) { target.onResume(); fragmentTransaction.show(target).hide(currentFragment); } else { fragmentTransaction.add(mContentId, target).show(target).hide(currentFragment); } fragmentTransaction.commit(); currentTab = i; if (mFragmentToogleListener != null) { mFragmentToogleListener.onToogleChange(target, currentTab); } } } }
private void setupRouter(final boolean multiWindow) { if (multiWindow) { fragmentTransaction = mock(FragmentTransaction.class); final FragmentManager fragmentManager = mock(FragmentManager.class); when(fragmentManager.beginTransaction()).thenReturn(fragmentTransaction); when(fragmentTransaction.replace(anyInt(), any(Fragment.class), anyString())).thenReturn(fragmentTransaction); when(activity.getSupportFragmentManager()).thenReturn(fragmentManager); } router = new Router(activity, multiWindow); }
/** * The {@code fragment} is added to the container view with id {@code tag}. The operation is * performed by the {@code fragmentManager}. * */ public static void addFragmentToActivity (final FragmentManager fragmentManager, final Fragment fragment, final String tag) { checkNotNull(fragmentManager); checkNotNull(fragment); final FragmentTransaction transaction = fragmentManager.beginTransaction(); transaction.add(fragment, tag); transaction.commit(); }