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

IndexOutOfBoundsException: Invalid item position when smoothScrollToPosition #11

Open
macsdragon opened this issue Sep 27, 2021 · 1 comment

Comments

@macsdragon
Copy link

macsdragon commented Sep 27, 2021

The mentioned exception occurs for instance when I filter the items in the list (change the items in the array and notifyDataSetChanged) > scroll to a position larger than 0 and > unfiltered the list > call smoothScrollToPosition(0). This also happens when the filter leaves only a single item in the list and then I unfiltered the list and > call smoothScrollToPosition(0). I was able to fix this problem by changing the CarouselLayoutManager#layoutItems method to use itemCount from RecyclerView.State.#getItemCount instead of RecyclerView#getItemCount. in the doc about RecyclerView#getItemCount it says "Note that this number is not necessarily equal to State#getItemCount() .In methods where State is available, you should use State#getItemCount() instead." I wonde r whether is better to pass the state also to to other methods in CarouselLayoutManager where item count is accessed directly through RecyclerView#getItemCount. Or would you expect any negative effects of this?

@macsdragon macsdragon changed the title IndexOutOfBoundsException: Invalid item position due to invalid item count IndexOutOfBoundsException: Invalid item position when smoothScrollToPosition Sep 27, 2021
@sparrow007
Copy link
Owner

@macsdragon so you are saying that state getItemCount is better than Recyclerview.getItemCount?
will check that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants