zoukankan      html  css  js  c++  java
  • 关于FragmentPageAdapter

    FragmentPagerAdapter:该类中每一个生成的Fragment都将保存在内存中,所以缺点非常明显,
    对于存在相对较多的fragment,程序将会吃掉非常多的内容。所以FragmentPagerAdapter适合那些相数量相对较少,
    静态的页面。对于存在多个fragment的情况,一般推荐使用FragmentStatePagerAdapter。


    1.getItem():
      
    不是继承自PagerAdapter,是FragmentPagerAdapter自身的一个函数,目的是生成我们需要的fragment。该方法会被FragmentPagerAdapter.instantiateItem()方法调用:
      @Override
      public Fragment getItem(int position) {
                Fragment fragment = new Fragment();
                Bundle bundle = new Bundle();
                bundle.putString("position", "" + position);
                fragment.setArguments(bundle);
                return fragment;
            }

    2.destoryItem()

      该函数被调用后,会对Fragment进行FragmentTransaction.detach(),并非删除,而是detach[解除附着]了,fragment依旧在FragmentManager的管理中,Fragment依旧会占有资源。

    3.instantiateItem()
      判断一下要生成的Fragment是否已经存在(FragmentPagerAdapter通过FragmentManager保留所有已经生成的fragment),如果存在,那么使用旧的fragment,旧的fragment将会被attach;如果不存在,就调用getItem()生成一个新的,新的对象将会被保存,并FragmentTransation.add()。

    你还有很多未完成的梦,你有什么理由停下脚步
  • 相关阅读:
    Windows下使用nmake编译C/C++的makefile
    poj 1228
    poj 1039
    poj 1410
    poj 3304
    poj 1113
    poj 2074
    uva 1423 LA 4255
    poj 1584
    poj 3277
  • 原文地址:https://www.cnblogs.com/quanziheng/p/13919851.html
Copyright © 2011-2022 走看看