Syntax for conditional statements in Android XML Layout

The correct syntax for calling a data-bind statement looks like "@{<some expression>}", and so a ternary conditional would be

"@{bool ? ifTrue : ifFalse}"

Where those two values would be the (unquoted) values of what you would normally place into the XML without data binding.

For example

android:color="@{isValid ? @color/green : @color/red}"

Or, you can import a class that has a static field that you need, for example

<data>
    <import type="android.view.View"/>
</data>

And

android:visibility="@{isVisible ? View.VISIBLE : View.GONE}"

Both of which are shown in the data binding documentation

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)