当前位置: 首页>>代码示例>>Java>>正文


Java FragmentTransaction.attach方法代码示例

本文整理汇总了Java中android.support.v4.app.FragmentTransaction.attach方法的典型用法代码示例。如果您正苦于以下问题:Java FragmentTransaction.attach方法的具体用法?Java FragmentTransaction.attach怎么用?Java FragmentTransaction.attach使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.support.v4.app.FragmentTransaction的用法示例。


在下文中一共展示了FragmentTransaction.attach方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setCurrentItem

import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
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();
}
 
开发者ID:jonashao,项目名称:Samantha,代码行数:21,代码来源:FragmentTransactionHelper.java

示例2: 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();
}
 
开发者ID:soramitsu,项目名称:iroha-demo-android,代码行数:22,代码来源:MainActivity.java

示例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();
        }
    }
 
开发者ID:ericberman,项目名称:MyFlightbookAndroid,代码行数:26,代码来源:MFBMain.java

示例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();
}
 
开发者ID:hsj-xiaokang,项目名称:OSchina_resources_android,代码行数:20,代码来源:NavFragment.java

示例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();
}
 
开发者ID:coding-dream,项目名称:TPlayer,代码行数:20,代码来源:NavFragment.java

示例6: onCreate

import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	final ActionBar actionbar = getSupportActionBar();
	actionbar.setDisplayHomeAsUpEnabled(true);
	actionbar.setHomeButtonEnabled(true);
	actionbar.setTitle(getIntent().getExtras().getString(
			Constants.PARAM_NAME));

	final FragmentManager fm = getSupportFragmentManager();
	Fragment f = fm.findFragmentByTag(GraphFragment.TAG);
	final FragmentTransaction ft = fm.beginTransaction();
	if (f == null) {
		f = GraphFragment.newInstance();
		f.setArguments(getIntent().getExtras());
		ft.add(android.R.id.content, f, GraphFragment.TAG);
	} else {
		ft.attach(f);
	}
	ft.commit();
}
 
开发者ID:CactusSoft,项目名称:zabbkit-android,代码行数:22,代码来源:GraphActivity.java

示例7: setCurrentItem

import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
public void setCurrentItem(int itemId, boolean addToStack) {
    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;
    if (addToStack) {
        fragmentTransaction.addToBackStack(name);
    }
    fragmentTransaction.commit();
}
 
开发者ID:jonashao,项目名称:Samantha,代码行数:24,代码来源:FragmentTransactionHelper.java

示例8: pop

import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
public void pop(TransitionAnimation animation) {
	List<Fragment> fragments = getFragments();
	int count = fragments.size();
	if (count == 0) {
		throw new IllegalStateException("Can't pop fragment when stack is empty.");
	}
	Fragment currentFragment = fragments.get(count - 1);
	Fragment previousFragment = count > 1 ? fragments.get(count - 2) : null;

	FragmentTransaction transaction = mFragmentManager.beginTransaction();
	if (previousFragment != null) {
		animation.applyBeforeFragmentTransactionExecuted(transaction, previousFragment, currentFragment);
	}
	transaction.remove(currentFragment);
	if (previousFragment != null) {
		transaction.attach(previousFragment);
	}
	transaction.commitNow();

	if (previousFragment != null) {
		animation.applyAfterFragmentTransactionExecuted(previousFragment, currentFragment);
	}
}
 
开发者ID:aartikov,项目名称:Alligator,代码行数:24,代码来源:FragmentStack.java

示例9: popUntil

import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
public void popUntil(Fragment fragment, TransitionAnimation animation) {
	List<Fragment> fragments = getFragments();
	int count = fragments.size();

	int index = fragments.indexOf(fragment);
	if (index == -1) {
		throw new IllegalArgumentException("Fragment is not found.");
	}

	if (index == count - 1) {
		return; // nothing to do
	}

	FragmentTransaction transaction = mFragmentManager.beginTransaction();
	for (int i = index + 1; i < count; i++) {
		if (i == count - 1) {
			animation.applyBeforeFragmentTransactionExecuted(transaction, fragment, fragments.get(i));
		}
		transaction.remove(fragments.get(i));
	}
	transaction.attach(fragment);
	transaction.commitNow();

	animation.applyAfterFragmentTransactionExecuted(fragment, fragments.get(count - 1));
}
 
开发者ID:aartikov,项目名称:Alligator,代码行数:26,代码来源:FragmentStack.java

示例10: 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);
	}
}
 
开发者ID:aartikov,项目名称:Alligator,代码行数:23,代码来源:FragmentSwitcher.java

示例11: 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();
    }
}
 
开发者ID:JulianAndroid,项目名称:AppChooser,代码行数:24,代码来源:FileInfosActivity.java

示例12: freshUI

import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
private void freshUI(){
	FragmentManager fragmentManager = getSupportFragmentManager();
	FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

	Fragment fragment = fragmentManager.findFragmentByTag(FreshNewsPostsFragment.TAG);
	if(fragment == null){
		fragment = new FreshNewsPostsFragment();
		fragmentTransaction.add(R.id.container,fragment,FreshNewsPostsFragment.TAG);
	}else{
		fragmentTransaction.attach(fragment);
	}

	fragmentTransaction.commit();
}
 
开发者ID:Gookler,项目名称:RxJanDan,代码行数:15,代码来源:NavigationDrawerActivity.java

示例13: 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;
}
 
开发者ID:okaybroda,项目名称:FragmentStateManager,代码行数:37,代码来源:FragmentStateManager.java

示例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;
}
 
开发者ID:CactusSoft,项目名称:zabbkit-android,代码行数:36,代码来源:FixedFragmentTabHost.java

示例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);
    }
}
 
开发者ID:JulianAndroid,项目名称:AppChooser,代码行数:30,代码来源:FileInfosActivity.java


注:本文中的android.support.v4.app.FragmentTransaction.attach方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。