Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>We finally managed to find a solution. Apparently our implementation suffered of two issues:</p> <ol> <li>our adapter did not remove the view in <code>destroyItem()</code>.</li> <li>we were caching views so that we'd have to inflate our layout just once, and, since we were not removing the view in <code>destroyItem()</code>, we were not adding it in <code>instantiateItem()</code> but just returning the cached view corresponding to the current position.</li> </ol> <p>I haven't looked too deeply in the source code of the <code>ViewPager</code> - and it's not exactly explicit that you have to do that - but the docs says :</p> <blockquote> <p><strong>destroyItem()</strong><br/>Remove a page for the given position. The adapter is responsible for removing the view from its container, although it only must ensure this is done by the time it returns from finishUpdate(ViewGroup).</p> </blockquote> <p>and: </p> <blockquote> <p>A very simple PagerAdapter may choose to use the page Views themselves as key objects, returning them from instantiateItem(ViewGroup, int) after creation and adding them to the parent ViewGroup. A matching destroyItem(ViewGroup, int, Object) implementation would remove the View from the parent ViewGroup and isViewFromObject(View, Object) could be implemented as return view == object;.</p> </blockquote> <p>So my conclusion is that <code>ViewPager</code> relies on its underlying adapter to explicitly add/remove its children in <code>instantiateItem()</code>/<code>destroyItem()</code>. That is, if your adapter is a subclass of <code>PagerAdapter</code>, your subclass must implement this logic.</p> <p>Side note: be aware of <a href="https://stackoverflow.com/questions/7290841/java-lang-illegalargumentexception-the-observer-is-null">this</a> if you use lists inside <code>ViewPager</code>.</p>
    singulars
    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.
    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