fragment的使用--备忘

本文详细介绍了Android中Fragment的使用,包括FragmentTransaction的add、replace方法,以及它们对Fragment生命周期的影响。还提到了在onDestroyView()中释放资源的重要性,并探讨了嵌套Fragments的概念,强调了getChildFragmentManager()和getFragmentManager()的区别,展示了如何在Fragment中添加和管理子Fragment。
摘要由CSDN通过智能技术生成

                                                 

首先要获取一个FragmentTransaction,这是一个提供多事务执行的一个类,用于执行与Fragment相关的事务,一个Transaction可以插入多个事务,即记录并管理多个操作。

 

f = Fragment.instantiate(this, fragmentName, args);
FragmentTransaction transaction = getFragmentManager().beginTransaction();

FragmentTransaction是一个抽象类,实现它的是BackStackRecord。

 

 

* add(...)

 

/**
     * Add a fragment to the activity state.  This fragment may optionally
     * also have its view (if {@link Fragment#onCreateView Fragment.onCreateView}
     * returns non-null) inserted into a container view of the activity.
     *

ity state.  This fragment may optionally
     * also have its view (if {@link Fragment#onCreateView Fragment.onCreateView}
     * returns non-null) inserted into a container view of the activity.
     *
     * @param containerViewId Optional identifier of the container this fragment is
     * to be placed in.  If 0, it will not be placed in a container.
     * @param fragment The fragment to be added.  This fragment must not already
     * be added to the activity.
     * @param tag Optional tag name for the fragment, to later retrieve the
     * fragment with {@link FragmentManager#findFragmentByTag

 * @param containerViewId O
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值