Android 使用ArrayPagerAdapter动态添加和删除选项卡
这是我第一次问的问题的延续。你对我使用错误的ArrayAdapter一窍不通,我只需要使用支持v4的ArrayAdapter。我已经把它的代码贴在下面了。我现在要讨论的下一个问题是在传递给SimplePageAdapter的ArrayList中创建PageDescriptor对象。我已经尝试将演示中使用的SimplePageDescriptor类复制并粘贴到我的代码中,但在尝试从Parceable.Creator方法返回时出错。它说SimplePageDescriptor在com.commonware.cwac.pager.SimplePageDescriptor中具有私有访问权限。我想我试图掌握的主要内容是如何在我自己的代码中使用演示中的SimplePageDescriptor。我是否只使用整个寻呼机文件夹?我已经在下面发布了我的SimplePageAdapter和SimplePageDescriptor代码Android 使用ArrayPagerAdapter动态添加和删除选项卡,android,fragmentpageradapter,commonsware-cwac,Android,Fragmentpageradapter,Commonsware Cwac,这是我第一次问的问题的延续。你对我使用错误的ArrayAdapter一窍不通,我只需要使用支持v4的ArrayAdapter。我已经把它的代码贴在下面了。我现在要讨论的下一个问题是在传递给SimplePageAdapter的ArrayList中创建PageDescriptor对象。我已经尝试将演示中使用的SimplePageDescriptor类复制并粘贴到我的代码中,但在尝试从Parceable.Creator方法返回时出错。它说SimplePageDescriptor在com.commonw
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];
}
};
我现在要讨论的下一个问题是在传递给SimplePageAdapter的ArrayList中创建PageDescriptor对象
PageDescriptor是一个接口。创建自己的类,例如实现接口的BlainePageDescriptor。这是一本书
我尝试将演示中使用的SimplePageDescriptor类复制并粘贴到代码中
那不能解决你的问题
据我所知,您的问题是希望您的ArrayPagerAdapter能够处理N种不同类型的页面JudgeMainFragment、JudgeClassifiyFragment等。。这要求您从createFragment返回正确的片段,给定提供的PageDescriptor。因此,您需要创建自己的页面描述符实现,例如BlainePageDescriptor。该类需要保留足够的信息,以满足PageDescriptor接口的要求,并能够告诉createFragment要创建哪种类型的片段。非常感谢您的帮助,我现在在代码中成功地使用了您库中的适配器。你对那些让我困惑的概念做了很好的解释,你给我的解决方案很有魅力。很抱歉,如果我的问题有点不着边际,但这让我困惑了3周,使用你的图书馆在几天内就把它清理干净了。再次感谢所有的帮助: