有人知道哪里有问题?我不能让页面更改监听器工作。我需要在页面更改但不能正常工作时获得实际位置。我找到了很多,但问题仍然存在。感谢时间。
公共类SuperFragmentHome扩展Fragment
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
PagerCustomHorizontalScrollView tabs = (PagerCustomHorizontalScrollView) view.findViewById(R.id.pagerTabs);
ViewPager pager = (ViewPager) view.findViewById(R.id.pager);
MyPagerAdapter adapter = new MyPagerAdapter(getChildFragmentManager());
pager.setAdapter(adapter);
//pager.setCurrentItem(1);
//pager.setOffscreenPageLimit(0);
//pager.getViewTreeObserver().addOnGlobalLayoutListener(new HomeFragment());
pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int i, float v, int i2) {
}
@Override
public void onPageSelected(int i) {
}
@Override
public void onPageScrollStateChanged(int i) {
}
});
tabs.setViewPager(pager);
}
我在SuperFragmentHome类中也有适配器类
public class MyPagerAdapter extends FragmentPagerAdapter {
DayCalculator dayCalc = new DayCalculator();
String s1 = dayCalc.getNameOfDayOfWeek(-1) + " " + dayCalc.getDateOfDayOfWeek(-1);
String s2 = dayCalc.getNameOfDayOfWeek(0) + " " + dayCalc.getDateOfDayOfWeek(0);
String s3 = dayCalc.getNameOfDayOfWeek(1) + " " + dayCalc.getDateOfDayOfWeek(1);
String s4 = dayCalc.getNameOfDayOfWeek(2) + " " + dayCalc.getDateOfDayOfWeek(2);
String s5 = dayCalc.getNameOfDayOfWeek(3) + " " + dayCalc.getDateOfDayOfWeek(3);
String s6 = dayCalc.getNameOfDayOfWeek(4) + " " + dayCalc.getDateOfDayOfWeek(4);
public MyPagerAdapter(FragmentManager fm) {
super(fm);
}
private final String[] TITLES = {s1, s2, s3, s4, s5, s6};
@Override
public CharSequence getPageTitle(int position) {
return TITLES[position];
}
@Override
public int getCount() {
return TITLES.length;
}
@Override
public Fragment getItem(int position) {
return HomeFragment.newInstance(position);
}
}