How to set visibility for include layout in databinding?

Poyyamozhi Ramakrishnan :

I have implemented data binding in my project. I have a particular screen with two nested layouts in include tags. I couldn't change the visibility for include layouts using data binding programmatically.

However, I have achieved it through a boolean, but my question is how to set visibility for that include tag programmatically.

My xml:

<include
  android:id="@+id/reg_email"
  layout="@layout/custom_email"
  android:layout_width="match_parent"
  android:layout_height="match_parent"/>


<include
  android:id="@+id/reg_phone"
  layout="@layout/custom_phone"
  android:layout_width="match_parent"
  android:layout_height="match_parent"/>

And in Activity: when I try to set this - it becomes red meaning it doesn't take it as a view.

  dataBinding.regPhone.setVisibility(View.GONE);
  dataBinding.regEmail.setVisibility(View.VISIBLE);
mahdi shahbazi :

add get root to your view

dataBinding.regPhone.getRoot().setVisibility(View.GONE);
dataBinding.regEmail.getRoot().setVisibility(View.VISIBLE);

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=133000&siteId=1