Search code examples
androiddata-bindingandroid-databindingandroid-switch

Switch case in Data Binding


Is it possible to write switch case with android Data Binding?

Suppose i have 3 conditions like

value == 1 then print A
value == 2 then print B
value == 3 then print C

Does there any way to do this stuff in xml by using Data Binding?

I know we can implement conditional statement like

android:visibility="@{age < 13 ? View.GONE : View.VISIBLE}"

But here i am searching for switch case statement.


Solution

  • No, as far as I know it is not possible and also would make the xml files really unreadable. I think it would be better to implement this in your business logic, not in layout files.