gpt4 book ai didi

android - FragmentPagerAdapter.getItem (int) 显示错误的 Fragment

转载 作者:行者123 更新时间:2023-11-29 14:18:01 26 4
gpt4 key购买 nike

我的FragmentPagerAdapter承载了ViewPager.OffScreenPageLimit的3个页面,始终显示最后加载的页面

我使用 ViewPager 来显示 fragment 。

我的 ViewPager

private static final int MONTH_SIZE = 12;

viewPager.setAdapter(new CalendarFragmentPagerAdapter(getChildFragmentManager()));
viewPager.setCurrentItem(GregorianCalendar.getInstance().get(Calendar.MONTH));
viewPager.setClickable(true);
viewPager.setSaveEnabled(false);
viewPager.setOffscreenPageLimit(1);

我的 FragmentPageAdapter:

    public class CalendarFragmentPagerAdapter extends FragmentPagerAdapter {

/**
* @param fm
*/
public CalendarFragmentPagerAdapter(FragmentManager fm) {
super(fm);
}

/**
*/
@Override
public Fragment getItem(int pageRequest) {
return new CalendarFragment(pageRequest);
}

/**
*/
@Override
public int getCount() {
return MONTH_SIZE - 1;
}

/**
*/
@Override
public CharSequence getPageTitle(int position) {
switch (position) {

case 0:
return getString(R.string.monthJanuary);

case 1:
return getString(R.string.monthFebruary);

case 2:
return getString(R.string.monthMarch);

case 3:
return getString(R.string.monthApril);

case 4:
return getString(R.string.monthMay);

case 5:
return getString(R.string.monthJune);

case 6:
return getString(R.string.monthJuly);

case 7:
return getString(R.string.monthAugust);

case 8:
return getString(R.string.monthSeptember);

case 9:
return getString(R.string.monthOctober);

case 10:
return getString(R.string.monthNovember);

case 11:
return getString(R.string.monthDecember);

default:
return "";
}
}

/**
* @hide
*/
@Override
public int getItemPosition(Object object) {
return POSITION_NONE;
}
}

我的 fragment :

// Nothing especial
List<CalendarEntry> events = getEvents(indexByCalendarFragmentPagerAdapter);

listView = (ListView) view.findViewById(R.id.listView_calendar_screen);

listView.setAdapter(new CalendarCustomAdapter(getActivity().getBaseContext(), events));

listView.setClickable(true);

错误是例如五月的展示,二月的事件

已经试了好几种方法都不能解决问题,谁能帮帮我?

最佳答案

只需将此代码或名为 getCount() 的函数更改为:

@Override
public int getCount() {
return events.length;
}

关于android - FragmentPagerAdapter.getItem (int) 显示错误的 Fragment,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24018245/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com