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.

Fragment之一:基本原理的更多相关文章

  1. Fragment之一:基本原理 分类: H1_ANDROID 2013-11-18 14:15 1642人阅读 评论(0) 收藏

    1.低版本API对Fragment的支持 Fragment必须被加载进Acitivity中,才能呈现.而在低于3.0版本的API中,由于不存在Fragment,因此必须使用support包: (1)对 ...

  2. 浅谈 Fragment 生命周期

    版权声明:本文为博主原创文章,未经博主允许不得转载. 微博:厉圣杰 源码:AndroidDemo/Fragment 文中如有纰漏,欢迎大家留言指出. Fragment 是在 Android 3.0 中 ...

  3. 札记:Fragment基础

    Fragment概述 在Fragment出现之前,Activity是app中界面的基本组成单位,值得一提的是,作为四大组件之一,它是需要"注册"的.组件的特性使得一个Activit ...

  4. EventBus实现activity跟fragment交互数据

    最近老是听到技术群里面有人提出需求,activity跟fragment交互数据,或者从一个activity跳转到另外一个activity的fragment,所以我给大家介绍一个开源项目,EventBu ...

  5. Android:Activity+Fragment及它们之间的数据交换.

    Android:Activity+Fragment及它们之间的数据交换 关于Fragment与Fragment.Activity通信的四种方式 比较好一点的Activity+Fragment及它们之间 ...

  6. Android中Fragment和ViewPager那点事儿(仿微信APP)

    在之前的博文<Android中使用ViewPager实现屏幕页面切换和引导页效果实现>和<Android中Fragment的两种创建方式>以及<Android中Fragm ...

  7. Android开发学习—— Fragment

    #Fragment* 用途:在一个Activity里切换界面,切换界面时只切换Fragment里面的内容* 生命周期方法跟Activity一致,可以理解把其为就是一个Activity* 定义布局文件作 ...

  8. Android中Fragment与Activity之间的交互(两种实现方式)

    (未给Fragment的布局设置BackGound) 之前关于Android中Fragment的概念以及创建方式,我专门写了一篇博文<Android中Fragment的两种创建方式>,就如 ...

  9. Android中Fragment的两种创建方式

    fragment是Activity中用户界面的一个行为或者是一部分.你可以在一个单独的Activity上把多个Fragment组合成为一个多区域的UI,并且可以在多个Activity中再使用.你可以认 ...

随机推荐

  1. (转) eclipse debug (调试) 学习心得

    1.Step Into (also F5) 跳入2.Step Over (also F6) 跳过3.Step Return (also F7) 执行完当前method,然后return跳出此metho ...

  2. xyiyy开始写博客了

    拖延症一直到现在才开始写博客... 希望写的博客对大家能有一些帮助,有不恰当或者不对的地方,还望大家指出. 以下为我的两个昵称:fraud xyiyy

  3. c中关于#与##的简易使用

    #运算符用于在预编译时,将宏参数转换为字符串 eg. #include <stdio.h>#define CONVERT(f)(#f) void helloworld(){ printf( ...

  4. [转]MySQL 5.6 全局事务 ID(GTID)实现原理(二)

    原文连接:http://qing.blog.sina.com.cn/1757661907/68c3cad333002qsk.html 原文作者:淘长源 转载注明以上信息 前文 MySQL 5.6 全局 ...

  5. LaTeX使用titlesec宏包改变章节编号形式的方法

    1.titleformat宏包命令详解 LaTeX中可以用titlesec宏包中的titleformat命令来改变标题形式: 导入宏包: \usepackage{titlesec} 改变标题的代码如下 ...

  6. LeetCode_Longest Consecutive Sequence

    Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...

  7. LeetCode_Jump Game

    Given an array of non-negative integers, you are initially positioned at the first index of the arra ...

  8. POP3、SMTP、IMAP和Exchange都是个什么玩意?

    很多时候一直对POP3.SMTP.IMAP和Exchange等迷迷糊糊的.下面就整理说明一下: 当前常用的电子邮件协议有SMTP.POP3.IMAP4,它们都隶属于TCP/IP协议簇,默认状态下,分别 ...

  9. Working——流程关系状态表

    --主表单 select * from ce_administration_procure t where t.id ='HZe992733d668dc6013d671df4760349'; --流程 ...

  10. tc令牌桶限速心得

    一.实验拓扑与实验现象 实验拓扑如图所示,在①号机上发送数据,③号机上接受数据,同时在④号机的eth1与eth2网口限制速率为115200kbps,命令如下 tc qdisc add dev eth1 ...