Retrieve a Fragment from a ViewPager

前端 未结 23 2535
逝去的感伤
逝去的感伤 2020-11-21 11:13

I\'m using a ViewPager together with a FragmentStatePagerAdapter to host three different fragments:

  • [Fragment1]
  • [Fragment2]<
23条回答
  •  逝去的感伤
    2020-11-21 11:57

    In Fragment

    public int getArgument(){
       return mPage;
    {
    public void update(){
    
    }
    

    In FragmentActivity

    List fragments = getSupportFragmentManager().getFragments();
    for(Fragment f:fragments){
        if((f instanceof PageFragment)&&(!f.isDetached())){
              PageFragment pf = (PageFragment)f;   
              if(pf.getArgument()==pager.getCurrentItem())pf.update();
        }
    }
    

提交回复
热议问题