Java Code Examples for android.support.v4.app.FragmentTransaction#detach()

The following examples show how to use android.support.v4.app.FragmentTransaction#detach() . 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: ManageCategoriesFragmentHandler.java    From mobikul-standalone-pos with MIT License 6 votes vote down vote up
public void saveCategoryToProduct(Product product, boolean isEdit) {
    if (categoryHashMap != null) {
        Iterator iterator = categoryHashMap.keySet().iterator();
        List<ProductCategoryModel> productCategories = new ArrayList<>();
        while (iterator.hasNext()) {
            String key = (String) iterator.next();
            Category value = categoryHashMap.get(key);
            ProductCategoryModel data = new ProductCategoryModel();
            data.setcId(value.getCId() + "");
            data.setName(value.getCategoryName() + "");
            productCategories.add(data);
        }
        if (product != null)
            product.setProductCategories(productCategories);
        Fragment fragment = ((BaseActivity) context).mSupportFragmentManager.findFragmentByTag(ManageCategoriesFragment.class.getSimpleName());
        FragmentTransaction ft = ((BaseActivity) context).mSupportFragmentManager.beginTransaction();
        ft.detach(fragment);
        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE);
        ft.commit();
        ((BaseActivity) context).mSupportFragmentManager.popBackStackImmediate();
    }
}
 
Example 2
Source File: ManageOptionFragmentHandler.java    From mobikul-standalone-pos with MIT License 6 votes vote down vote up
public void saveOptionToProduct(Product product, boolean isEdit) {
    List<Options> optionsList = new ArrayList<>();
    optionsList.addAll(product.getOptions());
    for (Options options : optionsList) {
        for (OptionValues optionValues : options.getOptionValues()) {
            if (optionValues.isSelected()) {
                options.setSelected(optionValues.isSelected());
                break;
            }
            options.setSelected(optionValues.isSelected());
        }
    }

    product.setOptions(optionsList);
    Fragment fragment = ((BaseActivity) context).mSupportFragmentManager.findFragmentByTag(ManageOptionValuesFragment.class.getSimpleName());
    FragmentTransaction ft = ((BaseActivity) context).mSupportFragmentManager.beginTransaction();
    ft.detach(fragment);
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE);
    ft.commit();
    ((BaseActivity) context).mSupportFragmentManager.popBackStackImmediate();
}
 
Example 3
Source File: MainActivity.java    From Androzic with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void addFragment(Fragment fragment, String tag)
{
	FragmentManager fm = getSupportFragmentManager();
	// Get topmost fragment
	Fragment parent;
	if (fm.getBackStackEntryCount() > 0)
	{
		FragmentManager.BackStackEntry bse = fm.getBackStackEntryAt(fm.getBackStackEntryCount() - 1);
		parent = fm.findFragmentByTag(bse.getName());
	}
	else
	{
		parent = fm.findFragmentById(R.id.content_frame);
	}
	FragmentTransaction ft = fm.beginTransaction();
	// Detach parent
	ft.detach(parent);
	// Add new fragment to back stack
	ft.add(R.id.content_frame, fragment, tag);
	ft.addToBackStack(tag);
	ft.commit();
}
 
Example 4
Source File: EnterTreatment.java    From HAPP with GNU General Public License v3.0 6 votes vote down vote up
public void refreshListFragments(){
    final FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    if (activeTreatmentsFragmentObject.isAdded()) {
        ft.detach(activeTreatmentsFragmentObject);
        ft.attach(activeTreatmentsFragmentObject);
    }
    if (todayTreatmentsFragmentObject.isAdded()) {
        ft.detach(todayTreatmentsFragmentObject);
        ft.attach(todayTreatmentsFragmentObject);
    }
    if (yestTreatmentsFragmentObject.isAdded()) {
        ft.detach(yestTreatmentsFragmentObject);
        ft.attach(yestTreatmentsFragmentObject);
    }
    ft.commit();
}
 
Example 5
Source File: NavigationDrawerActivity.java    From ZhihuDaily with Apache License 2.0 6 votes vote down vote up
@Override
public void onNavigationDrawerItemSelected(int position) {
    FragmentManager fragmentManager = getSupportFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

    Fragment lastFragment = fragmentManager.findFragmentByTag(getTag(mLastPosition));
    if (lastFragment != null) {
        fragmentTransaction.detach(lastFragment);
    }

    Fragment fragment = fragmentManager.findFragmentByTag(getTag(position));
    if (fragment == null) {
        fragment = getFragmentItem(position);
        fragmentTransaction.add(R.id.container, fragment, getTag(position));
    } else {
        fragmentTransaction.attach(fragment);
    }
    fragmentTransaction.commit();
    mLastPosition = position;

    mTitle = mNavigationFragment.getTitle(position);
    restortActionBar();
}
 
Example 6
Source File: ScreenCoordinator.java    From native-navigation with MIT License 6 votes vote down vote up
public void presentScreen(Fragment fragment, PresentAnimation anim, @Nullable Promise promise) {
  if (fragment == null) {
    throw new IllegalArgumentException("Fragment must not be null.");
  }
  BackStack bsi = new BackStack(getNextStackTag(), anim, promise);
  backStacks.push(bsi);
  // TODO: dry this up with pushScreen
  FragmentTransaction ft = activity.getSupportFragmentManager().beginTransaction()
      .setAllowOptimization(true)
      .setCustomAnimations(anim.enter, anim.exit, anim.popEnter, anim.popExit);

  Fragment currentFragment = getCurrentFragment();
  if (currentFragment != null && !isFragmentTranslucent(fragment)) {
    container.willDetachCurrentScreen();
    ft.detach(currentFragment);
  }
  ft
      .add(container.getId(), fragment)
      .addToBackStack(bsi.getTag())
      .commit();
  activity.getSupportFragmentManager().executePendingTransactions();
  bsi.pushFragment(fragment);
  Log.d(TAG, toString());
}
 
Example 7
Source File: PartFileActivity.java    From aMuleRemote with GNU General Public License v3.0 5 votes vote down vote up
public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
    if (mFragment != null) {
        // Detach the fragment, because another one is being attached
        FragmentTransaction realFT = getFT(ft);
        realFT.detach(mFragment);
        if (ft == null) realFT.commit();
    }
}
 
Example 8
Source File: MainActivity.java    From sms-ticket with Apache License 2.0 5 votes vote down vote up
@Override
public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
    String selectedTag = (tab.getPosition() == TAB_TICKETS) ? TAG_TICKETS : TAG_STATS;
    ProjectBaseFragment preInitializedFragment = (ProjectBaseFragment)getSupportFragmentManager()
        .findFragmentByTag(selectedTag);
    if (preInitializedFragment != null) {
        ft.detach(preInitializedFragment);
    } else if (mCurrentFragment != null) {
        ft.detach(mCurrentFragment);
    }
}
 
Example 9
Source File: BaseFragmentActivity.java    From umeng_community_android with MIT License 5 votes vote down vote up
/**
 * @param fragment
 */
public void detach(Fragment fragment) {
    if (null != fragment) {
        FragmentTransaction transaction = mFragmentManager.beginTransaction();
        transaction.detach(fragment);
        transaction.commit();
    }
}
 
Example 10
Source File: MainCarActivity.java    From carstream-android-auto with Apache License 2.0 5 votes vote down vote up
private void switchToFragment(String tag) {
    if (tag.equals(mCurrentFragmentTag)) {
        return;
    }
    FragmentManager manager = getSupportFragmentManager();
    Fragment currentFragment = mCurrentFragmentTag == null ? null : manager.findFragmentByTag(mCurrentFragmentTag);
    Fragment newFragment = manager.findFragmentByTag(tag);
    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    if (currentFragment != null) {
        transaction.detach(currentFragment);
    }
    transaction.attach(newFragment);
    transaction.commit();
    mCurrentFragmentTag = tag;
}
 
Example 11
Source File: FragmentStateManager.java    From FragmentStateManager with MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example 12
Source File: FragmentRecyclerAdapter.java    From RecyclerPager with Apache License 2.0 5 votes vote down vote up
/**
 * Detach Fragment
 */
@Override public void onViewRecycled(@NonNull FragmentViewHolder holder) {
    if (holder.currentFragment != null) {
        if (holder.currentFragment.getUserVisibleHint()) {
            holder.currentFragment.setMenuVisibility(false);
            holder.currentFragment.setUserVisibleHint(false);
        }
        FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
        fragmentTransaction.detach(holder.currentFragment);
        fragmentTransaction.commitNowAllowingStateLoss();
    }
    holder.currentFragment = null;
}
 
Example 13
Source File: FragmentRecyclerAdapter.java    From RecyclerPager with Apache License 2.0 5 votes vote down vote up
/**
 * Detach Fragment
 */
@Override public void onViewDetachedFromWindow(@NonNull FragmentViewHolder holder) {
    if (holder.currentFragment != null) {
        if (holder.currentFragment.getUserVisibleHint()) {
            holder.currentFragment.setMenuVisibility(false);
            holder.currentFragment.setUserVisibleHint(false);
        }
        FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
        fragmentTransaction.detach(holder.currentFragment);
        fragmentTransaction.commitNowAllowingStateLoss();
    }
    holder.currentFragment = null;
}
 
Example 14
Source File: RemotesFragment.java    From rcloneExplorer with MIT License 5 votes vote down vote up
private void refreshFragment() {
    if (getFragmentManager() == null) {
        return;
    }

    FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
    fragmentTransaction.detach(this);
    fragmentTransaction.attach(this);
    fragmentTransaction.commit();
}
 
Example 15
Source File: TwoWayViewActivity.java    From UltimateAndroid with Apache License 2.0 4 votes vote down vote up
@Override
public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
    if (mFragment != null) {
        ft.detach(mFragment);
    }
}
 
Example 16
Source File: MainActivity.java    From Androzic with GNU General Public License v3.0 4 votes vote down vote up
private void selectItem(int position)
{
	if (mDrawerAdapter.getSelectedItem() == position)
		return;
	
	DrawerItem item = mDrawerItems.get(position);
	// Actions
	if (item.type == DrawerItem.ItemType.INTENT)
	{
		if (position > 0)
			startActivity(item.intent);
	}
	// Fragments
	else if (item.type == DrawerItem.ItemType.FRAGMENT)
	{
		FragmentManager fm = getSupportFragmentManager();
		if (fm.getBackStackEntryCount() > 0)
		{
			fm.popBackStackImmediate(0, FragmentManager.POP_BACK_STACK_INCLUSIVE);
		}
		FragmentTransaction ft = fm.beginTransaction();
		Fragment parent = fm.findFragmentById(R.id.content_frame);
		if (parent != null)
		{
			ft.detach(parent);
		}
		Fragment fragment = fm.findFragmentByTag(item.name);
		if (fragment != null)
		{
			ft.attach(fragment);
		}
		else
		{
			ft.add(R.id.content_frame, item.fragment, item.name);
		}
		ft.commit();
		// update selected item and title, then close the drawer
		updateDrawerUI(item, position);
	}
	else if (item.type == DrawerItem.ItemType.ACTION)
	{
		Log.e(TAG, "ACTION");
		runOnUiThread(item.action);
	}
	mDrawerLayout.closeDrawer(mDrawerList);
}
 
Example 17
Source File: ArrayPagerAdapter.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
public void detach(Fragment fragment,
                   FragmentTransaction currTransaction) {
    currTransaction.detach(fragment);
}
 
Example 18
Source File: ArrayPagerAdapter.java    From cwac-pager with Apache License 2.0 4 votes vote down vote up
public void detach(Fragment fragment,
                   FragmentTransaction currTransaction) {
  currTransaction.detach(fragment);
}