我被指派创建一个非常不正常的布局,只能通过在另一个viewpager的第二个窗格中使用viewpager来完成,幸运的是,外部的viewpager需要被锁定,因此任务变得更加现实,然而出现了意外问题,即在内部viewpager加载后,onCreateView从未被调用过,我可以看到它在左右滑动,因此内部viewpager已经设置好了,但由于某种奇怪的原因它不会加载任何内部视图,请给予帮助,谢谢!
主要活动
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home_fragment);
pagePosition = 0;
setupViews();
}
private void setupViews() {
//setup images to be changed later
ivCategory = (ImageView) findViewById(R.id.ivCatergory);
ivHome = (ImageView) findViewById(R.id.ivHome);
ivProfile = (ImageView) findViewById(R.id.ivProfile);
//setup the viewpager
pager = (CustomViewPager) findViewById(R.id.viewpager);
//add fragments to the fragment array
pageList.add(NavigationFragment.newInstance(0, getApplicationContext(), this));
pageList.add(NavigationFragment.newInstance(1, getApplicationContext(), this));
pageList.add(NavigationFragment.newInstance(0, getApplicationContext(), this));
// initialize the page adapter
pageAdapter = new FragmentHomeAdapter(getSupportFragmentManager(), pageList);
//set the page adapter to the viewpager
pager.setAdapter(pageAdapter);
//set homepage to be first
pager.setCurrentItem(1);
//disable swiping to mimic iphone behaviour
pager.setPagingEnabled(false);
}
viewpager
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
int pageType = getArguments().getInt(PAGE_TYPE);
View v;
if (pageType == 1) {//all inner fragments will happen here
v = inflater.inflate(R.layout.fragment_container, container, false);
//setup the inner viewpager
pager = (CustomViewPager) v.findViewById(R.id.viewpager);
pageList.add(HomeFragment.newInstance(0, context, getActivity()));
pageList.add(HomeFragment.newInstance(1, context, getActivity()));
// initialize the page adapter
pageAdapter = new FragmentHomeAdapter(getActivity().getSupportFragmentManager(), pageList);
//set the page adapter to the viewpager
pager.setAdapter(pageAdapter);
pager.setPagingEnabled(true);
}
return v;
}
内部ViewPager
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v;
v = inflater.inflate(R.layout.fragment_list_feed, container, false);
lv = (ListView) v.findViewById(R.id.lvFeed);
listAdapter = new ListHomeAdapter(getArguments().getInt(PAGE_TYPE), feedListItems, getActivity());
//add header
header = (ViewGroup) inflater.inflate(R.layout.list_item_header, lv, false);
lv.addHeaderView(header, null, false);
lv.setAdapter(listAdapter);
if (getArguments().getInt(PAGE_TYPE) == 0) {
new getFeedListItems().execute();
} else {
new getFeedListItems().execute();
}
Toast.makeText(context, "This never shows",
Toast.LENGTH_SHORT).show();
return v;
}