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.** <p>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.</p>*/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.** <p class="note">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.</p>* * @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 FragmentManager之beginTransaction()相关推荐
- Android Fragment使用(三) Activity, Fragment, WebView的状态保存和恢复
Android中的状态保存和恢复 Android中的状态保存和恢复, 包括Activity和Fragment以及其中View的状态处理. Activity的状态除了其中的View和Fragment的状 ...
- 【Android】Fragment的简单笔记
被虐了,做某公司笔试时,发现自己连个Fragment的生命周期都写不详细.平时敲代码,有开发工具的便利,有网上各大神的文章,就算忘了也很容易的可以查到,但当要自己不借助外界,却发现自己似乎对该知识点并 ...
- Android系列之Fragment(一)----Fragment加载到Activity当中
参考文章出处: 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/3978989.html 前言 A ...
- Android 的 Fragment 教程
原文:Introduction to Android Fragments Tutorial 作者:Huyen Tue Dao 译者:kmyhy 一个 fragment 可以是任何东西,但在本文中,它是 ...
- Android第一行代码学习思考笔记(碎片、广播、持久化技术和Android数据库)
Android第一行代码学习思考笔记(碎片.广播.持久化技术和Android数据库 第四章 手机平板要兼顾--探究碎片 4.1碎片是什么(Fragment) 4.2碎片的使用方式 4.2.1碎片的简单 ...
- android 小练习(一) ---仿微信UI主界面
ActionBar 相信大家都用过微信,微信的界面我们从上往下看,首先是一个ActionBar,并且自定义了ActionProvider,就是那个"加号",里面有五个子菜单.今天就 ...
- Wcdb android 目录,wcdb使用笔记
本地数据加密 由于项目涉及到一些用户隐私数据的存储,所以需要对保存在客户端本地的数据进行加密,以防止用户隐私数据在设备被root的情况下出现泄漏.目前android的本地数据存储基本分为file,sh ...
- Android 4.0.3 联系人(通讯录)应用源码学习
Contacts应用入口类有2个:PeopleActivity.java和DialtactsActivity.java.PeopleActivity是联系人入口类,DialtactsActivity是 ...
- 底部导航栏的几种实现方式
概述 Android底部导航栏实现方式真的是太多了~在这里仅介绍几种实现方式~建议使用TabLayout +ViewPager ,TabLayout是Android Material Design中的 ...
最新文章
- Winform应用程序实现通用遮罩层二
- pycharm python 如何快速给代码块添加try/catch try/finally包裹?【ctrl+alt+T】
- InnoDB锁机制之Gap Lock、Next-Key Lock、Record Lock解析
- [转]I,P,B帧和PTS,DTS的关系
- list下界_下界理论
- AI队列长度检测:使用YOLO进行图像中的对象检测
- 在MyEclipse中配置Tomcat服务器
- CSS:transform
- 用CIL写程序:从“call vs callvirt”看方法调用
- 三码合一方法 制作QQ、微信、支付宝收款码合一
- XRD进行定性分析时可以得到哪些有用信息
- 刷armbian后必要的安装和配置
- mysql中if多重判断使用
- Python学员信息管理系统
- ipad查看电脑中的文件
- vs进行cuda编程失败,报错“the provided PTX was compiled with an unsupported toolchain.”
- 飞鸽传书——短信接口
- 用python读取身份证信息的功能分析与实现,兼述python调用dll的方法
- 微信分享网页链接自定义标题,图片,文字描述
- Java8 方法引用和Stream流