-
Notifications
You must be signed in to change notification settings - Fork 292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expanding parent view holder -> crash #198
Comments
Same issue here
|
I managed it by myself to expand a Recycler View. When I click on a parent I simply add the child models and remove them when I click another parent. |
@camino2007 @MDXDave I'm not able to reproduce this on the sample, any chance you can give more information on your implementation? Or better yet see if it occurs in one of our samples? |
same thing happens to me
|
Not sure if this info is relevant but it always crashes on position 14 (I have a list of 14 parent items) |
@pepitoria Any chance I can get a peek at your adapter and parent view holder implementations? is anything changing the data behind the scenes? Able to reproduce with the samples? |
Just figured it out. I was going through the adapter code to tidy it up a bit to post a gist here when I realise I still had the getItemCount method from my previous default non expandable implementation. As it was still overriding the parents getItemCount it was ok to override (no compilation errors) but of course it was not taking the sub items into consideration. I would strongly suggest to make getItemCount in ExpandableRecyclerAdapter.java as final so we cannot override it. It is a silly thing but I am sure most of us start with a default implementation and then look how to achieve the expandable behaviour. Hope this helps someone else too! |
@pepitoria Good catch! I'll wait and see if the others had this same problem as well. |
no problem @paul-turner, I take a pull request for just adding a 5 letter word to one java file would be a bit too much, right? haha |
Well at this point I'm on the fence whether that would be OK for users of the library. If someone wants to have a more custom expandable RV and overrides some of the methods to add in some behaviours on top of our adapter. An edge case but maybe something someone relies on (I've seen one example in past issues submitted here). At the very least may need to expand the docs to warn a little more. |
true that about expanding the docs with this. Another way could be to make getItemCount as final and use your own getExpandableItemCount method that could be overridden if needed. That way it would be obvious you are just "forgetting" to delete your getItemCount method. |
Added a note to the docs for now, will see if more issues like this roll in throughout the lifetime of the library. |
Hi guys,
I have following set up: In a support dialog fragment I have a simple RecyclerView where the parent views should be expandable. When I press the button to expand the children the app crashes with:
java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionViewHolder{24819493 position=19 id=-1, oldPos=6, pLpos:6 scrap [attachedScrap] tmpDetached no parent} at android.support.v7.widget.RecyclerView$Recycler.validateViewHolderForOffsetPosition(RecyclerView.java:4487) at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4618) at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4599) at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1988) at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1384) at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1347) at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:574) at android.support.v7.widget.RecyclerView.dispatchLayoutStep1(RecyclerView.java:2954) at android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:2594)
What I noticed is, that the crash occurs at position 19, but my children list contains only 18 elements.
The children list size is for each parent different.
I'm using com.android.support:recyclerview-v7:23.2.1
If you need any additional information, please let me know.
Your help is appreciated :)
Kind regards, Robert Hilse
The text was updated successfully, but these errors were encountered: