Skip to content
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

GridLayoutManager, spanSizeLookup, position is -1 #17

Closed
kjsolo opened this issue Apr 3, 2018 · 2 comments
Closed

GridLayoutManager, spanSizeLookup, position is -1 #17

kjsolo opened this issue Apr 3, 2018 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@kjsolo
Copy link

kjsolo commented Apr 3, 2018

// position == -1
// MoreViewItem is last item
spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() {
    override fun getSpanSize(position: Int): Int {
        val item = adapter.items[position] // ArrayIndexOutOfBoundsException
        if (item is MoreViewItem) {
            return 2
        }
        return 1
}

// notify insert
items.add(moreViewItem)
adapter.items = items
adapter.notifyItemInserted(items.lastIndex)
java.lang.ArrayIndexOutOfBoundsException: length=108; index=-1
        at java.util.ArrayList.get(ArrayList.java:439)
        at cn.soloho.xvideos.view.HomeFragment$onActivityCreated$$inlined$also$lambda$1.getSpanSize(HomeFragment.kt:57)
        at android.support.v7.widget.GridLayoutManager$SpanSizeLookup.getSpanGroupIndex(GridLayoutManager.java:971)
        at com.fondesa.recyclerviewdivider.extension.LayoutManagerExtensionsKt.getGroupIndex(LayoutManagerExtensions.kt:70)
        at com.fondesa.recyclerviewdivider.RecyclerViewDivider.getItemOffsets(RecyclerViewDivider.kt:104)
        at android.support.v7.widget.RecyclerView.getItemDecorInsetsForChild(RecyclerView.java:4792)
        at android.support.v7.widget.RecyclerView$LayoutManager.calculateItemDecorationsForChild(RecyclerView.java:9320)
        at android.support.v7.widget.GridLayoutManager.layoutChunk(GridLayoutManager.java:590)
        at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1519)
        at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:614)
        at android.support.v7.widget.GridLayoutManager.onLayoutChildren(GridLayoutManager.java:170)
        at android.support.v7.widget.RecyclerView.dispatchLayoutStep1(RecyclerView.java:3763)
        at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3527)
        at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:4082)
@fondesa fondesa self-assigned this Apr 3, 2018
@fondesa fondesa added the bug Something isn't working label Apr 3, 2018
fondesa added a commit that referenced this issue Apr 3, 2018
Fixed issue #17 avoiding computation when the position is invalid
@fondesa
Copy link
Owner

fondesa commented Apr 3, 2018

Fixed in 2.0.1.
I contributed also to your repository updating the dependency and removing the FIXME lines.

@fondesa fondesa closed this as completed Apr 3, 2018
@kjsolo
Copy link
Author

kjsolo commented Apr 4, 2018

Wow, Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants