Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is deliberate behavior of the <code>FastScroller</code>. When you call <code>setAdapter</code> on your <code>ListView</code>, the adapter is wrapped in a <code>HeaderViewListAdapter</code> if there are any headers set; this is why you must call <code>addHeaderView</code> before <code>setAdapter</code>. Then, in the <code>FastScroller</code> code, we see:</p> <pre><code> if (adapter instanceof HeaderViewListAdapter) { mListOffset = ((HeaderViewListAdapter)adapter).getHeadersCount(); adapter = ((HeaderViewListAdapter)adapter).getWrappedAdapter(); } </code></pre> <p>That is, get an offset and use the underlying adapter. <code>mListOffset</code> is then used to set the top position to scroll to with the fast scroller. So where does this wrapping actually happen? Up to, as expected, <code>ListView.addHeaderView</code>, where we see:</p> <pre><code> if (mHeaderViewInfos.size() &gt; 0|| mFooterViewInfos.size() &gt; 0) { mAdapter = new HeaderViewListAdapter(mHeaderViewInfos, mFooterViewInfos, adapter); } else { mAdapter = adapter; } </code></pre> <p>So we're definitely looking around the right place. Now, it sounds like your goal is to NOT have the offset behavior for list headers for your fast thumb, but otherwise have a normal list with header. To do this, it's sufficient (based on what we've seen of the code) to have <code>FastScroller.mListOffset = 0</code>. This is set only in <code>getSectionsFromIndexer</code>, which is called unconditionally in <code>init</code>, and conditionally in several other functions only when <code>mListAdapter == null</code>. <code>mListAdapter</code> is only null if <code>onSectionsChanged</code> gets called, so let's ignore that path for now.</p> <p>After a lot of digging around, and playing with various reflection hooks, I can say that there's no way to do this that will be even slightly future-compatible. You can use reflection to swap out the HeaderViewListAdapter for one that lies about its header count, etc; but that's quite fragile. Similarly, you can subclass the (package visible) FastScroller with one with your own behavior; but <code>mListOffset</code> is referenced widely and not through a getter, so this is even uglier than usual. Basically, you're running up against the fact that the system doesn't work quite the way you want.</p> <p>I hesitate to call this a bug, since it's so clear from the code that it's deliberate behavior. Have you considered making the first element of the list just a special first element (possibly using a custom <code>WrapperListAdapter</code> much like <code>HeaderViewListAdapter</code> if desired for book-keeping), rather than using the header mechanism?</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. 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