Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Thank you for your answer Shereef.</p> <p>I solved it a little bit differently.</p> <p>I changed the code of the ViewPager class of the android support library. The method <code>setCurrentItem(int)</code></p> <p>changes the page with animation. This method calls an internal method that requires the index and a flag enabling smooth scrolling. This flag is <code>boolean smoothScroll</code>. Extending this method with a second parameter <code>boolean smoothScroll</code> solved it for me. Calling this method <code>setCurrentItem(int index, boolean smoothScroll)</code> allowed me to make it scroll indefinitely.</p> <p>Here is a full example:</p> <p>Please consider that only the center page is shown. Moreover did I store the pages seperately, allowing me to handle them with more ease.</p> <pre><code>private class Page { View page; List&lt;..&gt; data; } // page for predecessor, current, and successor Page[] pages = new Page[3]; mDayPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageSelected(int position) { } @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {} @Override public void onPageScrollStateChanged(int state) { if (state == ViewPager.SCROLL_STATE_IDLE) { if (mFocusedPage == 0) { // move some stuff from the // center to the right here moveStuff(pages[1], pages[2]); // move stuff from the left to the center moveStuff(pages[0], pages[1]); // retrieve new stuff and insert it to the left page insertStuff(pages[0]); } else if (mFocusedPage == 2) { // move stuff from the center to the left page moveStuff(pages[1], pages[0]); // move stuff from the right to the center page moveStuff(pages[2], pages[1]); // retrieve stuff and insert it to the right page insertStuff(pages[2]); } // go back to the center allowing to scroll indefinitely mDayPager.setCurrentItem(1, false); } } }); </code></pre> <p>However, without Jon Willis Code I wouldn't have solved it myself. </p> <p>EDIT: here is a <a href="http://thehayro.blogspot.de/2013/09/infiniteviewpager-infinite-paging.html" rel="noreferrer">blogpost</a> about this: </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload