Closed kidd3166 closed 6 years ago
定位到是手动调用适配器的bindViewHolder出现的问题,请问你在bindViewHolder的实现那里,inflate布局的时候,是不是attachToParent参数置为true了?
// 手动调用创建标签 final RecyclerView.ViewHolder holder = mAdapter.createViewHolder(parent, type); mAdapter.bindViewHolder(holder, mPinnedHeaderPosition);
我也碰到一样的问题,inflate时attachToParent=false,也一样出现这个问题,
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)