Do you folks declare <view_ids.xml like this> or s...
# splitties
m
Do you folks declare view_ids.xml like this or simply write 1, 2, 3 etc?
l
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
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
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
The only reason to have IDs is saved state 😅
ah, RelativeLayout, almost forgot
l
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
yep, my problem arose exactly with labelFor