-
Notifications
You must be signed in to change notification settings - Fork 185
ViewHolder views must not be attached when created? #87
Comments
Code reference for the above error. Thanks in advance |
I had the same error after updating support libraries to version 27.1.0 |
@elitelokesh seems to be caused by The I found this workaround: override @Override
public GhostHeaderViewHolder onCreateGhostHeaderViewHolder(ViewGroup parent) {
final View ghostView = new View(parent.getContext());
ghostView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
return new GhostHeaderViewHolder(ghostView);
} |
@Dona278 your answer really help me Thanks. My problem is also 27.1.0 not working on that . |
Is there a release pending? |
I am facing the same issue is there any update on this issue? |
Same issue. |
I had found the solution for this View v = inflater.inflate(R.layout.ghost_view, parent, false); Please add an empty layout to onCreateGhostHeaderViewHolder |
@Dona278 Thanks very much! I've solved the problem. |
same error |
I tried @Dona278's solution but now my recyclerview is completely empty. Any ideas? Debugging execution, I noticed that after onCreateGhostHeaderViewHolder, no onCreateItemViewHolder is being called. I have a NestedScrollView, and inside is the RecyclerView. |
@Dona278 Thanks very much! I've solved the problem. |
@Dona278 Thanks!!! I solved the problem. |
@Dona278 thanks!! |
Fix problem "ViewHolder views must not be attached when created" on androidx. Applying patch from ShamylZakariya#87 (comment)
@Dona278 Thank you! |
@Dona278 hey Thank you , I have migrated my project into AndoridX so had a problem so i tried your solution and it perfectly worked ! |
After a year seeing that my workaround still helps makes me happy! 🎉 |
@Dona278 Thank you! You saved the day for me :) |
I tried @Dona278 solution now above issue cleared but recyclerview is empty(showing nothing). I'm using 'com.android.support:appcompat-v7:27.1.1' & 'org.zakariya.stickyheaders:stickyheaders:0.7.6'. Please update if any solution. |
Hi @MuruganSKutty |
I found another cause of invisible recyclerview, i.e (Recylerview is present inside the NestedScrollView). Please any help @Dona278 , @TothSteven . |
Hi @MuruganSKutty |
Hey I want to apologize to everybody. My job has been very demanding, and I've had to ignore all this. I've fixed the bug, and am upgrading to androidx, newer gradle etc. I will push a release in the next few days. |
@Dona278 @chandmohd i have updated to AndroidX and in my customer Adapter the one extending the SectionAdapter i have override the same method and it still gives me the same problem |
thanks man. it's really working |
@Dona278 thanks for the answer mate, it's really helpful. |
02-28 05:16:37.431 1676-1676/com.elite.foodrepublic.dev E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.elite.foodrepublic.dev, PID: 1676
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 android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5869)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5752)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5748)
at org.zakariya.stickyheaders.StickyHeaderLayoutManager.onLayoutChildren(StickyHeaderLayoutManager.java:200)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3812)
at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3529)
at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:4082)
at android.view.View.layout(View.java:19659)
at android.view.ViewGroup.layout(ViewGroup.java:6075)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1083)
at android.view.View.layout(View.java:19659)
at android.view.ViewGroup.layout(ViewGroup.java:6075)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:19659)
at android.view.ViewGroup.layout(ViewGroup.java:6075)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1083)
at android.view.View.layout(View.java:19659)
at android.view.ViewGroup.layout(ViewGroup.java:6075)
at android.support.design.widget.CoordinatorLayout.layoutChild(CoordinatorLayout.java:1191)
at android.support.design.widget.CoordinatorLayout.onLayoutChild(CoordinatorLayout.java:876)
at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:895)
at android.view.View.layout(View.java:19659)
at android.view.ViewGroup.layout(ViewGroup.java:6075)
at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1171)
at android.view.View.layout(View.java:19659)
at android.view.ViewGroup.layout(ViewGroup.java:6075)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:19659)
at android.view.ViewGroup.layout(ViewGroup.java:6075)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1791)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1635)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1544)
at android.view.View.layout(View.java:19659)
at android.view.ViewGroup.layout(ViewGroup.java:6075)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:19659)
at android.view.ViewGroup.layout(ViewGroup.java:6075)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1791)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1635)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1544)
at android.view.View.layout(View.java:19659)
at android.view.ViewGroup.layout(ViewGroup.java:6075)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at com.android.internal.policy.DecorView.onLayout(DecorView.java:761)
at android.view.View.layout(View.java:19659)
at android.view.ViewGroup.layout(ViewGroup.java:6075)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2496)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2212)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1392)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6752)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
02-28 05:16:37.431 1676-1676/com.elite.foodrepublic.dev E/AndroidRuntime: at android.view.Choreographer.doCallbacks(Choreographer.java:723)
at android.view.Choreographer.doFrame(Choreographer.java:658)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
The text was updated successfully, but these errors were encountered: