[ChipGroup] Copy last value instead IndexOutOfBoundsException
See original GitHub issueDescription: When iterating over collection with indices (in case collection size is bigger than 1) if we add +1 index there’ll be copy chip of last value instead IndexOutOfBoundsException.
Source code:
for (i in tags.indices + 1) {
val chip = Chip(tagsChipGroup.context).apply {
text = tags[i]
setChipBackgroundColorResource(R.color.colorCardBackground)
isClickable = true
textSize = resources.getDimension(R.dimen.tag_text_size)
}
tagsChipGroup.addView(chip)
}
Android API version: 29
Material Library version: 1.1.0-beta02
Device: Pixel 2 XL
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Material Chips: java.lang.IndexOutOfBoundsException when ...
I have a chip group with some chips in my AddItemFragment . I am creating these chips programmatically. To be more precise here...
Read more >ChipGroup - Android Developers
A ChipGroup is used to hold multiple Chip s. By default, the chips are reflowed across multiple lines. Set the app:singleLine attribute to ......
Read more >WolframAlpha v1.4.19.2022041167 (Patched).apk
Allows applications to open network sockets. android.permission.ACCESS_NETWORK_STATE, Allows applications to access information about networks.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey @papuge! This looks like a Kotlin questions that doesn’t really relate to our library.
With that said, in your original code snippet you have
for (i in tags.indices + 1)
. Whattags.indices + 1
is actually doing is creating anIntArray
of the indices in yourtags
Collection
and then appending theInt
1 to that array, leaving you with the equivalent offor (i in [0, 1, 2, 1]
(given atags
array with 3 items in it). This is more obvious if you replace1
with something like99
.tags.indices + 99
creates anIntArray
of the indices intags
and appends theInt
99, leaving you with[0, 1, 2, 99]
. In that case, you would get anIndexOutOfBounds
exception if yourtags
array had less than 99 items in it.Hopefully that helps. I’m going to go a head and close this issue.
@hunterstich this is tag collection
val tags = arguments?.getStringArrayList(ARG_TAGS)?.toList()!!
and piece of OnCreateView() method