Android(安卓)FragmentManager之beginTransaction()
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();
更多相关文章
- Android实现Bitmap高斯模糊效果
- Android(安卓)控件GridView使用案例讲解
- 获取 + 查看 Android(安卓)源码的 方法
- Android之MotionLayout(三),用 MotionLayout 来做过渡动画,如何
- Android异步处理二:使用AsyncTask异步更新UI界面
- Android异步处理二:使用AsyncTask异步更新UI界面
- android ui显示技巧和注意事项
- 【Android(安卓)Developer Blog】Android(安卓)Studio 2.0(07 APR
- Android高手进阶教程(五)之----Android(安卓)中LayoutInflater的