Fragment之一:基本原理 分类: H1_ANDROID 2013-11-18 14:15 1642人阅读 评论(0) 收藏
1、低版本API对Fragment的支持
Fragment必须被加载进Acitivity中,才能呈现。而在低于3.0版本的API中,由于不存在Fragment,因此必须使用support包:
(1)对于1.6(API=4)及以上版本:
创建Fragment时,应该继承android.support.v4.app.Fragment;
创建Activity时,应该继承android.support.v4.app.FragmentActivity;
(2)对于2.1(API=7)及以上版本:(为同时支撑ActionBar)
创建Fragment时,应该继承android.support.v4.app.Fragment;(这个还需要确认一下)
创建Activity时,应该继承android.support.v7.app.ActionBarActivity
(3)他们之间的关系为:
java.lang.Object
↳ android.content.Context
↳ android.content.ContextWrapper
↳android.view.ContextThemeWrapper
↳android.app.Activity
↳android.support.v4.app.FragmentActivity
↳android.support.v7.app.ActionBarActivity
2、addToBackStack()
Keep in mind that when you perform fragment transactions, such as replace or remove one, it's often appropriate to allow the user to navigate backward
and "undo" the change. To allow the user to navigate backward through the fragment transactions, you must call addToBackStack() before you commit the FragmentTransaction.
3、Fragment之间的通信
To allow a Fragment to communicate up to its Activity, you can define an interface in the Fragment class and implement it within the Activity.
版权声明:本文为博主原创文章,未经博主允许不得转载。
最新文章
- RMS:Microsoft Office检测到您的信息权限管理配置有问题。有关详细信息,请与管理员联系。(转)
- kafka性能参数和压力测试揭秘
- 洛谷P1220关路灯[区间DP]
- WCF Security(转载)
- Ubuntu下配置L2TP
- Sqlserver Sql Agent Job 只能同时有一个实例运行
- samba配置smb.conf
- char与byte差异
- php memcached+Mysql(主从)
- Docker跨主机网络——overlay
- Python数据结构应用2——Queue
- Flume1.9.0的安装、部署、简单应用(含分布式、与Hadoop3.1.2、Hbase1.4.9的案例)
- POM文件分析记
- python练习七—P2P下载
- Confluence 6 为空白空间重置原始默认内容
- java模式:建造者模式
- [No0000F5]C# 类(Class)
- php实现网站四则运算。
- 【Cmd】那些年,我们迷恋的cmd命令(一)
- VUX