Guys, I'm writing an application on Android. Schedule for uni. There is a SQLite database with the daily schedule itself (2 school weeks). After the Start Screen, the schedule for the current day opens and you need to go to the next or previous one when you swipe.
So, how to make it so that when it reaches Friday, the next svaype to the right again opens Monday? I tried Swipe Views with FragmentPagerAdpter, but there you need to specify a specific number of pages, and in the end the flipping ends. Tell me how to better implement it, where to dig and what material to read.
- and if you put a listener on the svayp and do a check, if it is Friday to load Monday - Kirill Stoianov
|
2 answers
As a solution, I can suggest to assign a listener to the ViewPager:
@Override public void onPageScrollStateChanged (int state) { if (state == ViewPager.SCROLL_STATE_IDLE) { int current = viewPager.getCurrentItem(); if (curr == 4) { viewPager.setCurrentItem(0, false); } } }
|
Improved this option, added 2 pages after Friday and before Monday for uploading, and if this page opens, flips it back to the original day, for a beautiful animation.
@Override public void onPageScrollStateChanged(int state) { if (state == ViewPager.SCROLL_STATE_IDLE) { int current = mViewPager.getCurrentItem(); if (current == 6 ) { mViewPager.setCurrentItem(1, false); // Переход после пятницы, на оригинальный понедельник } else if (current == 0) { mViewPager.setCurrentItem(5, false); } } }}); @Override public Fragment getItem(int position) { int CurrentDay = position; if (position == 0) { return CardViewActivity.newInstance(2); //Подгрузка пятницы перед понедельником } else { return CardViewActivity.newInstance(position - 3); } }
|