I have a daily scheduler function that you can access it. The schedule is for a week, so each fragment of the FragmentStatePagerAdapter corresponds to a day. When I access it, it is always on MONDAY, then I can swipe left and to TUESDAY. Please help, I have been searching the internet for a long time!
PROBLEM: Once I know the day, how do I make the FragmentStatePagerAdapter start with the fragment for that day, and show the schedule that was pre-designed for the day?
EX: If it is THURSDAY, it open THUR, then I can swipe left to WEDNESDAY or swipe right to FRIDAY?
public PagerAdapterScheduler (Context context, FragmentManager fm, String[] arrayDayInWeek) {
super(fm);
this.mContext = context;
this.fragmentManager = fm;
this.arrayDayInWeek = arrayDayInWeek;
}
@Override
public Fragment getItem(int i) {
return FragmentDay.newInstance(i, arrayDayInWeek[i]);
}
@Override
public int getCount() {
return this.arrayDayInWeek.length;
}
Here is the instantiation of the individual fragment of a day (in another FragmentDay.class):
public static final FragmentDay newInstance (int dayNumber, String dayLabel) {
FragmentDay fragment = new FragmentDay();
Bundle bundle = new Bundle();
bundle.putInt( "dayNumber", dayNumber );
bundle.putString( "dayLabel", dayLabel );
fragment.setArguments( bundle );
return fragment;
}
SOLUTION:
Thank you for suggesting this. I have tried it before but now it works. Here is the catch:
You need to SET-ADAPTER before you SET-CURRENT-ITEM:
mViewPager.setAdapter(mPagerAdapterScheduler);
mViewPager.setCurrentItem( Calendar.getInstance().get(Calendar.DAY_OF_WEEK) );