oubowu / PinnedSectionItemDecoration

A powerful ItemDecoration for Recyclerview, supports the common layoutmanager.
Apache License 2.0
2.09k stars 218 forks source link

bug in android support 27.1.0 #43

Closed kidd3166 closed 6 years ago

kidd3166 commented 6 years ago

java.lang.IllegalStateException: ViewHolder views must not be attached when created. Ensure that you are not passing 'true' to the attachToRoot parameter of LayoutInflater.inflate(..., boolean attachToRoot) at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:6687) at com.oushangfeng.pinnedsectionitemdecoration.PinnedHeaderItemDecoration.createPinnedHeader(PinnedHeaderItemDecoration.java:298) at com.oushangfeng.pinnedsectionitemdecoration.PinnedHeaderItemDecoration.onDraw(PinnedHeaderItemDecoration.java:147)

oubowu commented 6 years ago

定位到是手动调用适配器的bindViewHolder出现的问题,请问你在bindViewHolder的实现那里,inflate布局的时候,是不是attachToParent参数置为true了? // 手动调用创建标签 final RecyclerView.ViewHolder holder = mAdapter.createViewHolder(parent, type); mAdapter.bindViewHolder(holder, mPinnedHeaderPosition);

xie2000 commented 5 years ago

我也碰到一样的问题,inflate时attachToParent=false,也一样出现这个问题,