Android FragmentStatePagerAdapter, how to tag a fragment to find it later

前端 未结 9 1197
独厮守ぢ
独厮守ぢ 2020-12-24 14:09

When using the FragmentStatePageAdapter I get the fragments like this:

    @Override
    public Fragment getItem(int position) {
        return          


        
9条回答
  •  时光说笑
    2020-12-24 14:57

    Create a holder to hold the new SuperCoolFragment object. Then tag and return the holder object.

    @Override
    public Fragment getItem(int position) {
        SuperCoolFragment superCoolFragment = new SuperCoolFragment();
        superCoolFragment.setTag(YOUR_TAG);
        return superCoolFragment;
    }
    

提交回复
热议问题