android - FragmentPagerAdapter.getItem (int) shows wrong Fragment -


my fragmentpageradapter carries 3 pages of viewpager.offscreenpagelimit , displays last loaded page

i use viewpager display fragments.

my 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); 

my 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;     } } 

my 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); 

the error e.g. displays in month of may, events of february

already tried several ways , not solve problem, can me?

simply change code or function called getcount() :

@override public int getcount() {     return events.length; } 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -