Fragment之一:基本原理


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.

转载于:https://www.cnblogs.com/jinhong-lu/p/4559490.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值