# FragmentTransaction add 和 replace 完全解析

2015/08/28 00:33

#FragmentTransaction FragmentTransaction是fragment的管理工具，可进行fragment的添加,移除,替换,以及执行其他操作。可以通过FragmentManager获取其实例。

fragmentManager.beginTransaction();


Add a fragment to the activity state. This fragment may optionally also have its view (if Fragment.onCreateView returns non-null) into a container view of the activity.

Parameters containerViewId Optional identifier of the container this fragment is to be placed in. If 0, it will not be placed in a container. fragment The fragment to be added. This fragment must not already be added to the activity. tag Optional tag name for the fragment, to later retrieve the fragment with FragmentManager.findFragmentByTag(String). Returns Returns the same FragmentTransaction instance.

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

Replace an existing fragment that was added to a container. This is essentially the same as calling remove(Fragment) for all currently added fragments that were added with the same containerViewId and then add(int, Fragment, String) with the same arguments given here.

java.lang.IllegalArgumentException：No view found for id for fragment


0
3 收藏

0 评论
3 收藏
0