https://kotlinlang.org logo
Title
m

miha-x64

08/31/2021, 10:48 AM
Do you folks declare view_ids.xml like this or simply write 1, 2, 3 etc?
l

louiscad

08/31/2021, 11:51 AM
I do it like this when I need savedState. Otherwise, I just give no id at all, and they are generated automatically if I use Views DSL ConstraintLayout.
m

miha-x64

08/31/2021, 1:26 PM
Yep, for saving state. I was using simple IDs starting with 1, but it turns out that generateViewId does the same, so when I started using labelFor, I got several collisions at once 😂
Now I want to call generateViewId one hundred times to reserve these IDs for myself
l

louiscad

08/31/2021, 3:31 PM
You can also just call it when you need it, on the fly, if you don't need savedState.
Note that these will not clash with the xml defined ones.
m

miha-x64

08/31/2021, 3:45 PM
The only reason to have IDs is saved state 😅
ah, RelativeLayout, almost forgot
l

louiscad

08/31/2021, 3:46 PM
Nope. Other reasons are accessibility labels (labelFor) and ConstraintLayout, which work fine with generated ones. But if you do need saved state, use xml ids, it's the easiest and most reliable since it shouln't have duplicates by mistake.
m

miha-x64

08/31/2021, 3:48 PM
yep, my problem arose exactly with labelFor