Is there any practice how to initialize bunch of p...
# splitties
i
Is there any practice how to initialize bunch of properties for single view? It looks like that the order is important from performance and result perspectives. For example, isChecked property for ToggleButton adds some time for initialization, and moreover its position in initialization influences the result (if it is before `textOn`/`textOff`, then
text
property should be initialized, and if it is after - everything works without this extra property). Maybe the is some technique for initialization in one transaction, without intermediate UI invalidation?
For example, should I call
setCompoundDrawables
or
text
after all related properties (like
padding
,
isAllCaps
,
setTypeFace
) are set?
l
I don't think it matters much. Layout is not done at initialization time anyway, so many things are scheduled for the next layout pass.
i
UI invalidation != UI redraw. Your changes will not be applied immediately, but will be scheduled to the next UI thread tick. So do whatever you want in any order you want. It does not matter at all.
i
@ilyagulya There is at least one difference I've found: isChecked property for ToggleButton. It should be set after textOn/textOff is set. Otherwise toggle button is shown with default I/O labels instead of given ones.
i
@ispbox that’s widget-specific problem. My answer was about your first question. There’s no such thing as view initialization transaction. Android framework (mostly) designed to apply all changes on the next UI tick. Some widgets could behave differently, of course, but you need to deal with it on your own.
👍 1