我在其他内部实现了一个视图寻呼机。要求是在父视图寻呼机上设置标签并在子视图寻呼机上显示其项目。例如,父视图寻呼机有两个标签(剧集,视频),我们有多个剧集和视频(子视图寻呼机),需要在相应的标签中显示。问题是当我从屏幕边缘滑动时,即使当前选项卡有更多要加载的项目,它也会更改选项卡。但是当我从屏幕中央滑动并且当我在剧集标签上显示下一集时,它工作正常。
这是一段代码:
public class ParentPagerAdapter extends FragmentStatePagerAdapter {
private List<String> tabList;
private boolean isPilot;
private ArrayList<?extends IVideoModel> videoList;
private ArrayList<?extends IEpisodeAndVideoModel> episodeList;
public ParentPagerAdapter(FragmentManager fm, List<String> tabList,
ArrayList<?extends IEpisodeModel> episodeList, ArrayList<?extends IVideoModel>
videoList) {
super(fm);
this.episodeList = episodeList;
this.videoList = videoList;
this.tabList = tabList;
}
@Override
public Fragment getItem(int position) {
Fragment fragment;
Bundle bundle = new Bundle();
if(tabList.get(position).contains(VIDEOS_TAB_TITLE)){
fragment = new VideoTabFragment();
return fragment;
}else if(tabList.get(position).contains(EPISODES_TAB_TITLE)){
fragment = new EpisodeTabFragment();
return fragment;
}
return null;
}
@Override
public int getCount() {
return tabList.size();
}
@Override
public CharSequence getPageTitle(int position) {
return tabList.get(position);
}
@Override
public int getItemPosition(Object object){
return PagerAdapter.POSITION_NONE;
}
}
儿童观点寻呼机1:
public class ProjectVideoPagerAdapter extends PagerAdapter {
public final String TAG = ProjectVideoPagerAdapter.class.getCanonicalName();
private Context mContext;
private LayoutInflater mLayoutInflator;
private RowProjectLandingPagerItemBinding itemBinding;
private List<? extends IVideoModel> projectVideoList;
public ProjectVideoPagerAdapter(Context context, List<? extends IVideoModel> projectVideoList) {
mContext = context;
this.projectVideoList = projectVideoList;
mLayoutInflator = ((LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE));
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
debugLog("Entering instantiateItem with position = " + position);
itemBinding =
DataBindingUtil.inflate(mLayoutInflator, R.layout.row_project_landing_pager_item, null,
false);
if (projectVideoList == null) return null;
container.addView(itemBinding.getRoot());
debugLog("Exiting instantiateItem()");
return itemBinding.getRoot();
}
@Override
public int getCount() {
if (projectVideoList != null && !projectVideoList.isEmpty()) return projectVideoList.size();
return 0;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == (object);
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
((ViewPager)container).removeView((View)object);
//super.destroyItem(container, position, object);
}
}
儿童视图寻呼机2:
public class ProjectVideoPagerAdapter extends PagerAdapter {
public final String TAG = ProjectVideoPagerAdapter.class.getCanonicalName();
private Context mContext;
private LayoutInflater mLayoutInflator;
private RowProjectLandingPagerItemBinding itemBinding;
private List<? extends IEpisodeModel> projectEpisodeList;
public ProjectVideoPagerAdapter(Context context, List<? extends IEpisodeModel> projectList) {
mContext = context;
this.projectEpisodeList = projectList;
mLayoutInflator = ((LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE));
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
debugLog("Entering instantiateItem with position = " + position);
itemBinding =
DataBindingUtil.inflate(mLayoutInflator, R.layout.row_project_landing_pager_item, null,
false);
if (projectEpisodeList == null) return null;
container.addView(itemBinding.getRoot());
debugLog("Exiting instantiateItem()");
return itemBinding.getRoot();
}
@Override
public int getCount() {
if (projectEpisodeList != null && !projectEpisodeList.isEmpty()) return projectEpisodeList.size();
return 0;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == (object);
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
((ViewPager)container).removeView((View)object);
//super.destroyItem(container, position, object);
}
}