Vinay KG
Vinay KG

Reputation: 39

Textview Visibility using Data Binding

I am trying the below Usecase :

  1. There are Two Items in the List
  2. Two TextViews / Button are displayed in a List ( RecyclerView )
  3. First TextView / Button is Clicked
  4. Second TextView / Button needs to be Hidden ( Toggle the Visibility ) after clicking on First TextView

enter image description here

I am not able to achieve this functionality using Data Binding. Suggestions are welcomed

Upvotes: 0

Views: 274

Answers (1)

Baki Kocak
Baki Kocak

Reputation: 389

Your question is that much clear for me but in general:

<TextView
   android:visibility="@{user.firstName != null ? View.VISIBLE: View.GONE} 
   ...
</TextView>

Supposing that you use User class and depending on a property you can switch visibility of a view:

<layout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools">
      <data>
          <variable name="user" type="com.example.User"/>
       </data>
        <!-- ... rest of layout here -->
</layout>

If you want to achieve this with a button, you might need to update the property as OnClick action of the button.

Upvotes: 1

Related Questions