bgogetap / StickyHeaders

Easily add Sticky Headers to your RecyclerView
Apache License 2.0
521 stars 88 forks source link

getAdapter position returns INVALID_POSITION #66

Closed jeekiran closed 6 years ago

jeekiran commented 6 years ago

Click to expansion and collapse has been added to the source .But when i tap header after few scroll in child list getAdapterPosition return -1. for the click.but sticky header keeps its position as expected. When i scroll back and the first child will be bellow the header it return the adapter position as expected.

Is there any way to get the visible header position when scrolled

bgogetap commented 6 years ago

One of the convenient things about this library is that it uses the same ViewHolders for the sticky headers as are used for the RecyclerView itself. The downside to this is that the ViewHolder used for the sticky header is no longer associated with the adapter. This means using getAdapterPosition on a sticky header is not reliable and should be avoided in all cases.

I'd recommend associating what the header represents by some other means than position in the data set.

One possible solution to this is using view tags to keep an updated reference on the position the sticky header represents. However I think using position is less than ideal, so I probably won't be personally adding it any time soon.

bgogetap commented 6 years ago

Closing this as I think the best solution is to get the position that the header represents by checking in your dataset.

The only workaround I could add is what I suggested before, but that will still leave you with a broken getAdapterPosition method.