DataBinding with custom variablesintboolean

suggest change

A show/hide flag does not need its own model class. Data binding accepts basic types for that kind of operation.

<layout xmlns:android="http://schemas.android.com/apk/res/android">

    <data>

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

        <variable
            name="selected"
            type="Boolean" />

    </data>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hello World"
            android:visibility="@{selected ? View.VISIBLE : View.GONE}" />

    </RelativeLayout>
</layout>

and set its value from java class.

binding.setSelected(true);

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents