davideas / FlexibleAdapter

Fast and versatile Adapter for RecyclerView which regroups several features into one library to considerably improve the user experience :-)
Apache License 2.0
3.55k stars 553 forks source link

Classcast Exception #737

Closed vdotm closed 5 years ago

vdotm commented 5 years ago

I am using eu.davidea:flexible-adapter:5.1.0' to show expandable list view headers in recyclerview. However, there is a case, where I would like to disable sticky headers. So in view holder class, that extends from ExpandableViewHolder. I am setting the stickyHeader to false using this constructor super(view, adapter, false);//True for sticky

When the recycler view item is updated, I get the following exception

java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to androidx.recyclerview.widget.RecyclerView$LayoutParams at androidx.recyclerview.widget.RecyclerView$LayoutManager.getLeftDecorationWidth(RecyclerView.java:9492) at eu.davidea.flexibleadapter.helpers.StickyHeaderHelper.applyLayoutParamsAndMargins(StickyHeaderHelper.java:275) at eu.davidea.flexibleadapter.helpers.StickyHeaderHelper.ensureHeaderParent(StickyHeaderHelper.java:262) at eu.davidea.flexibleadapter.helpers.StickyHeaderHelper.updateHeader(StickyHeaderHelper.java:173) at eu.davidea.flexibleadapter.helpers.StickyHeaderHelper.updateOrClearHeader(StickyHeaderHelper.java:138) at eu.davidea.flexibleadapter.FlexibleAdapter$AdapterDataObserver$1.run(FlexibleAdapter.java:5336) at android.os.Handler.handleCallback(Handler.java:789) at android.os.Handler.dispatchMessage(Handler.java:98) at android.os.Looper.loop(Looper.java:164)

What am I missing ? Can you please help?

davideas commented 5 years ago

@vdotm, You must keep that constructor with true if you have element with sticky headers in your project. To disable sticky headers you must use the Adapter function.

vdotm commented 5 years ago

Thanks a lot for the quick reply. I was able to set it through the adapter function.