您的位置:首页 > 其它

activity- (ViewPager)--->Fragment

2016-03-18 10:09 381 查看
activity的布局中书写ViewPager,然后将Fragment加入到ViewPager中

通过FragmentTransaction.add( xxx,xxx,xxx)

/**

* Add a fragment to the activity state. This fragment may optionally

* also have its view (if {@link Fragment#onCreateView Fragment.onCreateView}

* returns non-null) inserted into a container view of the activity.

*

* @param containerViewId Optional identifier of the container this fragment is

* to be placed in. If 0, it will not be placed in a container.

* @param fragment The fragment to be added. This fragment must not already

* be added to the activity.

* @param tag Optional tag name for the fragment, to later retrieve the

* fragment with {@link FragmentManager#findFragmentByTag(String)

* FragmentManager.findFragmentByTag(String)}.

*

* @return Returns the same FragmentTransaction instance.

*/

public abstract FragmentTransaction add(int containerViewId, Fragment fragment, String tag);

/**

* Calls {@link #replace(int, Fragment, String)} with a null tag.

*/

public abstract FragmentTransaction replace(int containerViewId, Fragment fragment);

/**

* Replace an existing fragment that was added to a container. This is

* essentially the same as calling {@link #remove(Fragment)} for all

* currently added fragments that were added with the same containerViewId

* and then {@link #add(int, Fragment, String)} with the same arguments

* given here.

*

* @param containerViewId Identifier of the container whose fragment(s) are

* to be replaced.

* @param fragment The new fragment to place in the container.

* @param tag Optional tag name for the fragment, to later retrieve the

* fragment with {@link FragmentManager#findFragmentByTag(String)

* FragmentManager.findFragmentByTag(String)}.

*

* @return Returns the same FragmentTransaction instance.

*/

public abstract FragmentTransaction replace(int containerViewId, Fragment fragment, String tag);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: