As we know we don't need to create object of our control/view when using DataBinding, but what if we want to hide some views based on a condition.
For example, i want to hide TextView of email when there is no data for email. Here is small code snippet for that.
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="user"
type="<package name>.UserModel" />
<import type="android.view.View"/>
</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="@{user.email}"
android:visibility="@{user.email.trim().length()>0 ? View.VISIBLE : View.GONE}"/>
</RelativeLayout>
</layout>