java.lang.IllegalStateException: Can't change tag of fragment

后端 未结 6 1171
情书的邮戳
情书的邮戳 2020-12-05 07:39

Hi i am getting this error while using a pageViwer and Adapter to slide across 3 fragments.

here is my pageAdapter

public class FreedomPageAdapter ex         


        
6条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-05 08:00

    You have created an instance of SubscribedFragment() class

    savedListFragment = new SubscribedFragment();
    

    and then you passed the list of this objects into ViewPager Adpater:

    FreedomPageAdapter(FragmentManager fm, List listFragment)
    

    which receives List of Fragment type in its constructor. Since the constructor receives List of Fragment type, try to cast each savedListFragment into Fragment before you add it to the list and then pass it to the adpater's constructor:

    fragmentList.add((Fragment)savedListFragment);
    viewPager.setAdapter(new FreedomPageAdapter(fragmentManager(), fragmentList));
    

提交回复
热议问题