0

This is a continuation from the question I 1st asked here, Creating a new ArrayPagerAdapter with variety of Fragments. You were dead on about me using the wrong ArrayAdapter I just needed to use the one that has v4 support. I have posted the code for it below. One of the next blocks i'm getting stuck on right now is creating the PageDescriptor objects in the ArrayList passed into SimplePageAdapter. I've tried copying and pasting the SimplePageDescriptor class used in the Demo into my code but I am getting an error when trying to return from the Parceable.Creator method. It says SimplePageDescriptor has private access in com.commonsware.cwac.pager.SimplePageDescriptor. I guess the main thing i'm trying to grasp is how to use the SimplePageDescriptor from the demo in my own code. Do I just use the entire pager folder? I have posted my code for the SimplePagerAdapter and the SimplePageDescriptor below.

 class SimplePagerAdapter extends ArrayPagerAdapter<android.support.v4.app.Fragment> {



    public SimplePagerAdapter(FragmentManager fragmentManager,
                              ArrayList<PageDescriptor> descriptors) {
        super(fragmentManager, descriptors);
    }

    @Override
    protected Fragment createFragment(PageDescriptor desc) {

        mMainFragment = JudgeMainFragment.newInstance();

        mClassifyFragment = JudgeClassifyFragment.newInstance();

        mSidebarFragment = JudgeSidebarFragment.newInstance((SidebarCall) mActivity);


        mVerdictFragment = JudgeVerdictFragment.newInstance();



        return (mMainFragment.newInstance());


    }
}





public static final Parcelable.Creator<com.commonsware.cwac.pager.SimplePageDescriptor> CREATOR=
  new Parcelable.Creator<com.commonsware.cwac.pager.SimplePageDescriptor>() {
    public com.commonsware.cwac.pager.SimplePageDescriptor createFromParcel(Parcel in) {
      //This is the line I get the error at
      return new com.commonsware.cwac.pager.SimplePageDescriptor(in);
    }

    public com.commonsware.cwac.pager.SimplePageDescriptor[] newArray(int size) {
      return new com.commonsware.cwac.pager.SimplePageDescriptor[size];
    }
  };
Community
  • 1
  • 1
Blaine
  • 31
  • 6

1 Answers1

0

One of the next blocks i'm getting stuck on right now is creating the PageDescriptor objects in the ArrayList passed into SimplePageAdapter

PageDescriptor is an interface. Create your own class (e.g., BlainePageDescriptor) that implements the interface. This is covered in the documentation.

I've tried copying and pasting the SimplePageDescriptor class used in the Demo into my code

That will not solve your problem.

Your problem, as I understand it, is that you want your ArrayPagerAdapter to be able to handle N different types of pages (JudgeMainFragment, JudgeClassifyFragment, etc.). That requires you to return the proper fragment from createFragment(), given the supplied PageDescriptor. Hence, you need to create your own PageDescriptor implementation (e.g., BlainePageDescriptor). That class needs to hold onto sufficient information to both satisfy the PageDescriptor interface and be able to tell createFragment() what sort of fragment to create.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • You are awesome thanks for all your help I am now successfully using the adapter from your library in my code. You gave great explanations over the concepts that were confusing me and the solutions you gave me worked like a charm. Sorry if my questions were a little noobish but this had me confused for 3 weeks and using your library cleared it up in a couple of days. Once again thanks for all the help :) – Blaine Oct 20 '15 at 02:13