使用: 
    private Fragment fragment;    private FragmentManager fm;    fm = getSupportFragmentManager();    fragment = fm.findFragmentById(R.id.fragment_container);    fm.beginTransaction()                    .add(R.id.fragment_container, fragment)                    .commit();


beginTransaction源码:

 /**     * Start a series of edit operations on the Fragments associated with     * this FragmentManager.     *     * 

Note: A fragment transaction can only be created/committed prior * to an activity saving its state. If you try to commit a transaction * after {@link FragmentActivity#onSaveInstanceState FragmentActivity.onSaveInstanceState()} * (and prior to a following {@link FragmentActivity#onStart FragmentActivity.onStart} * or {@link FragmentActivity#onResume FragmentActivity.onResume()}, you will get an error. * This is because the framework takes care of saving your current fragments * in the state, and if changes are made after the state is saved then they * will be lost.

*/ public abstract FragmentTransaction beginTransaction();

add源码:

/**     * Calls {@link #add(int, Fragment, String)} with a null tag.     */    public abstract FragmentTransaction add(@IdRes int containerViewId, Fragment fragment);

commit源码:

 /**     * Schedules a commit of this transaction.  The commit does     * not happen immediately; it will be scheduled as work on the main thread     * to be done the next time that thread is ready.     *     * 

A transaction can only be committed with this method * prior to its containing activity saving its state. If the commit is * attempted after that point, an exception will be thrown. This is * because the state after the commit can be lost if the activity needs to * be restored from its state. See {@link #commitAllowingStateLoss()} for * situations where it may be okay to lose the commit.

* * @return Returns the identifier of this transaction's back stack entry, * if {@link #addToBackStack(String)} had been called. Otherwise, returns * a negative number. */ public abstract int commit();

更多相关文章

  1. Android实现Bitmap高斯模糊效果
  2. Android(安卓)控件GridView使用案例讲解
  3. 获取 + 查看 Android(安卓)源码的 方法
  4. Android之MotionLayout(三),用 MotionLayout 来做过渡动画,如何
  5. Android异步处理二:使用AsyncTask异步更新UI界面
  6. Android异步处理二:使用AsyncTask异步更新UI界面
  7. android ui显示技巧和注意事项
  8. 【Android(安卓)Developer Blog】Android(安卓)Studio 2.0(07 APR
  9. Android高手进阶教程(五)之----Android(安卓)中LayoutInflater的

随机推荐

  1. Android(安卓)发布release版本的apk软件
  2. Android应用资源全面分析之三:Drawable资
  3. 预习数据存储5种方式
  4. Android(安卓)7.0 增加以太网设置DHCP和
  5. android 编程小技巧(持续中)
  6. Android仿QQ侧滑菜单
  7. 为你的Android(安卓)App实现自签名的 SSL
  8. android 6.0 Launcher3 去掉抽屉式,显示
  9. Android采用SharedPreferences保存用户登
  10. Android:解决全屏界面到带有状态栏界面切