sergejsha / pinned-section-listview

Easy to use ListView with pinned sections for Android.
2.59k stars 808 forks source link

Section item does not stay pinned #39

Open mbeaty opened 10 years ago

mbeaty commented 10 years ago

I have a list with just one list item (TextView) per section. That single list item's TextView contains wrapping text that can potentially consume the entire height of the ListView's container. If this is the case, I am finding that the pinned section item does not stay pinned, but rather it disappears only to reappear at the time the next section item is scrolled into view. To reproduce this, simply create the list with one ITEM per SECTION, and make the text for the item section very long - long enough to extend beyond the height of the ListView's container. I am observing this with the example app and have no other customization at all.

Update: To clarify, my test actually does the above, but my test list has 10 such sections, each with identical items, just for testing purposes. Again, only one item per section.

mbeaty commented 10 years ago

This is the code causing this issue:

void ensureShadowForPosition(int sectionPosition, int firstVisibleItem, int visibleItemCount) {
   if (visibleItemCount < 2) { // no need for creating shadow at all, we have a single visible item           
         destroyPinnedShadow();
         return;
    }
    ...
}

I commented out this if block and it works fine. It seems that you are assuming here that a one item list would never be scrollable, therefore the shadow would be unnecessary. However, if the ListView's container is small enough in height, and the item's text length is such that the list can scroll, the shadow would still be useful, and desired. So, I think you need to somehow take into account whether the view is still scrollable, and not just look at whether visibleItemCount < 2. Does this make sense, and would you agree with this? Thank you.

Update: Actually, on further analysis, I think you can just remove the above if block with no ill effect. Please advise.

sajith666 commented 9 years ago

Thank you for this.