How to set visibility for include layout in databinding?
A better way.
On the top layout, declare the boolean or an observable field whose value toggle the visibility of the included layout. Then remember to give the included layout an id
else it wont work
<?xml version="1.0" encoding="utf-8"?>
<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>
<import type="android.view.View"/>
<variable
name="show"
type="Boolean" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:background="@color/colorPrimary">
<include layout="@layout/progress"
android:id="@+id/progress"
android:visibility="@{show?View.VISIBLE:View.GONE}"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
add get root to your view
dataBinding.regPhone.getRoot().setVisibility(View.GONE);
dataBinding.regEmail.getRoot().setVisibility(View.VISIBLE);