timehop / sticky-headers-recyclerview

[UNMAINTAINED] Sticky Headers decorator for Android's RecyclerView
Apache License 2.0
3.74k stars 755 forks source link

Only last header is visible #165

Open graisVictory opened 5 years ago

graisVictory commented 5 years ago

The issue reproduces periodically without any rules. onCreateHeaderViewHolder and onBindHeaderViewHolder gets called, but headers are not visible My code looks like

override fun getHeaderId(position: Int): Long {
    return clients[position].companyName.toUpperCase().get(0).toLong()
}
override fun onCreateHeaderViewHolder(parent: ViewGroup): HeaderHolder {
    val view = LayoutInflater.from(parent.context).inflate(R.layout.item_client_list_header, parent, false)
     return HeaderHolder(view)
}
override fun onBindHeaderViewHolder(holder: HeaderHolder, position: Int) {
    val letter = clients[position].companyName.get(0).toUpperCase().toString()
    holder.bind(letter)
}

and xml:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    style="@style/SansMediumBig"
    tools:text="A"
    android:layout_width="match_parent"
    android:padding="@dimen/padding_small"
    android:background="@color/transparent_grey_3"/>

But no matter what font or any other style (even without any style) I'm using - result is the same. Note that I'm using this recycle view https://github.com/myinnos/AlphabetIndex-Fast-Scroll-RecyclerView Help me please :(

maroney-tm commented 5 years ago

It's a bit late but I was getting all sorts of weird behavior when the my recyclerview was set to android:layout_height="wrap_content". All the issues went away when I swapped to android:layout_height="match_parent". I had my recyclerview as a child in a relative layout.

My issue was that that onCreateHeaderViewHolder and onBindHeaderViewHolder were being called but the view wasn't showing. Just an empty view, of the correct size, where it should have been. Strangely the last several stickyHeaders would show up.

lkesteloot commented 5 years ago

@graisVictory did you figure this out? I'm getting the same behavior: The callbacks are called but only the last header is correct. The other ones are blank and much too tall. I don't think it's related to @maroney-tm's solution because my layout_weight="1", meaning that the height shouldn't depend on content.

lkesteloot commented 5 years ago

Okay found the problem in my case: The list view hadn't been laid out yet, so any header on-screen initially got laid out wrong.