本文整理汇总了Java中android.support.v4.app.FragmentTransaction.detach方法的典型用法代码示例。如果您正苦于以下问题:Java FragmentTransaction.detach方法的具体用法?Java FragmentTransaction.detach怎么用?Java FragmentTransaction.detach使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v4.app.FragmentTransaction
的用法示例。
在下文中一共展示了FragmentTransaction.detach方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: switchFragment
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
private void switchFragment(@NonNull Fragment fragment, String tag) {
if (fragment.isAdded()) {
return;
}
final FragmentManager manager = getSupportFragmentManager();
final FragmentTransaction fragmentTransaction = manager.beginTransaction();
final Fragment currentFragment = manager.findFragmentById(R.id.container);
if (currentFragment != null) {
fragmentTransaction.detach(currentFragment);
}
if (fragment.isDetached()) {
fragmentTransaction.attach(fragment);
} else {
fragmentTransaction.add(R.id.container, fragment, tag);
}
fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
.commit();
}
示例2: addTab
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
private static void addTab(MFBMain activity, TabHost tabHost, TabHost.TabSpec tabSpec, TabInfo tabInfo) {
// Attach a Tab view factory to the spec
tabSpec.setContent(activity.new TabFactory(activity));
String tag = tabSpec.getTag();
// Check to see if we already have a fragment for this tab, probably
// from a previously saved state. If so, deactivate it, because our
// initial state is that a tab isn't shown.
tabInfo.fragment = activity.getSupportFragmentManager().findFragmentByTag(tag);
if (tabInfo.fragment != null && !tabInfo.fragment.isDetached()) {
FragmentTransaction ft = activity.getSupportFragmentManager().beginTransaction();
ft.detach(tabInfo.fragment);
ft.commit();
activity.getSupportFragmentManager().executePendingTransactions();
}
tabHost.addTab(tabSpec);
}
示例3: onTabChanged
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
public void onTabChanged(String tag) {
TabInfo newTab = this.mapTabInfo.get(tag);
if (mLastTab != newTab) {
FragmentTransaction ft = this.getSupportFragmentManager().beginTransaction();
if (mLastTab != null) {
if (mLastTab.fragment != null) {
ft.detach(mLastTab.fragment);
}
}
if (newTab != null) {
if (newTab.fragment == null) {
newTab.fragment = Fragment.instantiate(this,
newTab.clss.getName(), newTab.args);
ft.add(R.id.realtabcontent, newTab.fragment, newTab.tag);
} else {
ft.attach(newTab.fragment);
}
}
mLastTab = newTab;
ft.commit();
this.getSupportFragmentManager().executePendingTransactions();
}
}
示例4: doTabChanged
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
private void doTabChanged(NavigationButton oldNavButton, NavigationButton newNavButton) {
FragmentTransaction ft = mFragmentManager.beginTransaction();
if (oldNavButton != null) {
if (oldNavButton.getFragment() != null) {
ft.detach(oldNavButton.getFragment());
}
}
if (newNavButton != null) {
if (newNavButton.getFragment() == null) {
Fragment fragment = Fragment.instantiate(mContext,
newNavButton.getClx().getName(), null);
ft.add(mContainerId, fragment, newNavButton.getTag());
newNavButton.setFragment(fragment);
} else {
ft.attach(newNavButton.getFragment());
}
}
ft.commit();
}
示例5: switchFragment
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
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();
}
示例6: addTab
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
public final void addTab(final TabHost.TabSpec tabSpec,
final Class<?> clss, final 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.commit();
}
}
mTabs.add(info);
addTab(tabSpec);
}
示例7: push
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
public void push(Fragment fragment, TransitionAnimation animation) {
Fragment currentFragment = getCurrentFragment();
FragmentTransaction transaction = mFragmentManager.beginTransaction();
if (currentFragment != null) {
animation.applyBeforeFragmentTransactionExecuted(transaction, fragment, currentFragment);
transaction.detach(currentFragment);
}
int index = getFragmentCount();
transaction.add(mContainerId, fragment, getFragmentTag(index));
transaction.commitNow();
if (currentFragment != null) {
animation.applyAfterFragmentTransactionExecuted(fragment, currentFragment);
}
}
示例8: switchTo
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
public void switchTo(Fragment fragment, TransitionAnimation animation) {
List<Fragment> fragments = getFragments();
boolean isNewFragment = !fragments.contains(fragment);
Fragment currentFragment = getCurrentFragment();
FragmentTransaction transaction = mFragmentManager.beginTransaction();
if (currentFragment != null) {
animation.applyBeforeFragmentTransactionExecuted(transaction, fragment, currentFragment);
transaction.detach(currentFragment);
}
if (isNewFragment) {
transaction.add(mContainerId, fragment, getFragmentTag(fragments.size()));
} else {
transaction.attach(fragment);
}
transaction.commitNow();
if (currentFragment != null) {
animation.applyAfterFragmentTransactionExecuted(fragment, currentFragment);
}
}
示例9: showDirectoryWithSelectedTab
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
private void showDirectoryWithSelectedTab(FileInfo fileInfo) {
Preconditions.checkNotNull(fileInfo, "fileInfo == null");
Preconditions.checkNotNull(mSelectedDirectory, "mSelectedDirectory == null");
Log.d(TAG, "showDirectoryWithSelectedTab: " + fileInfo.getName());
if (mSelectedDirectory != fileInfo) {
FragmentTransaction ft = mFragmentManager.beginTransaction();
Fragment f = mFragmentManager.findFragmentByTag(mSelectedDirectory.getAbsolutePath());
if (f != null && !f.isDetached()) {
ft.detach(f);
}
mSelectedDirectory = fileInfo;
f = mFragmentManager.findFragmentByTag(fileInfo.getAbsolutePath());
if (f == null) {
f = FileInfosFragment.newInstance(fileInfo.getAbsolutePath());
ft.add(R.id.contentFrame, f, fileInfo.getAbsolutePath());
} else {
ft.attach(f);
}
ft.commit();
}
}
示例10: changeFragment
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
/**
* 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;
}
示例11: onDestroyView
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
@Override public void onDestroyView() {
super.onDestroyView();
vp.removeAllViews();
FragmentTransaction fragmentTransaction = getChildFragmentManager().beginTransaction();
fragmentTransaction.detach(listFragments.get(0));
fragmentTransaction.detach(listFragments.get(1));
fragmentTransaction.commitAllowingStateLoss();
}
示例12: onDestroyView
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
@Override public void onDestroyView() {
super.onDestroyView();
System.out.println("B onDestroyView");
vp.removeAllViews();
FragmentTransaction fragmentTransaction = getChildFragmentManager().beginTransaction();
fragmentTransaction.detach(list.get(0));
fragmentTransaction.detach(list.get(1));
fragmentTransaction.commitAllowingStateLoss();
//unbinder.unbind();
}
示例13: onAttachedToWindow
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
String currentTab = getCurrentTabTag();
// Go through all tabs and make sure their fragments match
// the correct state.
FragmentTransaction ft = null;
for (int i = 0; i < mTabs.size(); i++) {
TabInfo tab = mTabs.get(i);
tab.fragment = mFragmentManager.findFragmentByTag(tab.tag);
if (tab.fragment != null && !tab.fragment.isDetached()) {
if (tab.tag.equals(currentTab)) {
// The fragment for this tab is already there and
// active, and it is what we really want to have
// as the current tab. Nothing to do.
mLastTab = tab;
} else {
// This fragment was restored in the active state,
// but is not the current tab. Deactivate it.
if (ft == null) {
ft = mFragmentManager.beginTransaction();
}
ft.detach(tab.fragment);
}
}
}
// We are now ready to go. Make sure we are switched to the
// correct tab.
mAttached = true;
ft = doTabChanged(currentTab, ft);
if (ft != null) {
ft.commit();
mFragmentManager.executePendingTransactions();
}
}
示例14: doTabChanged
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
private FragmentTransaction doTabChanged(final String tabId,
FragmentTransaction ft) {
TabInfo newTab = null;
for (int i = 0; i < mTabs.size(); i++) {
TabInfo tab = mTabs.get(i);
if (tab.tag.equals(tabId)) {
newTab = tab;
}
}
if (newTab == null) {
throw new IllegalStateException("No tab known for tag " + tabId);
}
FragmentTransaction fragmentTransaction = ft;
if (!newTab.equals(mLastTab)) {
if (fragmentTransaction == null) {
fragmentTransaction = mFragmentManager.beginTransaction();
}
if (mLastTab != null) {
if (mLastTab.fragment != null) {
fragmentTransaction.detach(mLastTab.fragment);
}
}
if (newTab.fragment == null) {
newTab.fragment = Fragment.instantiate(mContext,
newTab.clss.getName(), newTab.args);
newTab.fragment.setRetainInstance(mIsRetanedFragments);
fragmentTransaction.add(mContainerId, newTab.fragment,
newTab.tag);
} else {
fragmentTransaction.attach(newTab.fragment);
}
mLastTab = newTab;
}
return fragmentTransaction;
}
示例15: showDirectoryWithBackPressed
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
private void showDirectoryWithBackPressed() {
Preconditions.checkNotNull(mSelectedDirectory, "mSelectedDirectory == null");
Preconditions.checkArgument(mDirectories.contains(mSelectedDirectory),
"mDirectories not contain:" + mSelectedDirectory.getAbsolutePath());
final int selectedPosition = mDirectories.indexOf(mSelectedDirectory);
if (selectedPosition == 0) {
finish();
} else {
FragmentTransaction ft = mFragmentManager.beginTransaction();
Fragment f = mFragmentManager.findFragmentByTag(mSelectedDirectory.getAbsolutePath());
if (f != null && !f.isDetached()) {
ft.detach(f);
}
int previousPosition = selectedPosition - 1;
FileInfo previous = mSelectedDirectory = mDirectories.get(previousPosition);
f = mFragmentManager.findFragmentByTag(previous.getAbsolutePath());
if (f == null) {
f = FileInfosFragment.newInstance(previous.getAbsolutePath());
ft.add(R.id.contentFrame, f, previous.getAbsolutePath());
} else {
ft.attach(f);
}
ft.commit();
Message msg = mMyHandler.obtainMessage();
msg.arg1 = previousPosition;
mMyHandler.sendMessageDelayed(msg, 100L);
}
}