Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not resolve the two-way binding attribute 'visibility' on type 'android.support.constraint.Group'

I have two groups defined inside a ConstraintLayout in my layout. I want them to have visibility opposite to each other. So if group1 is visible then group2 should be gone and vice versa. I am trying to use data binding to achieve this.

<data>

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

</data>

<android.support.constraint.Group
                    android:id="@+id/group1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:visibility="visible"
                    app:constraint_referenced_ids="..." />

<android.support.constraint.Group
                    android:id="@+id/group2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:visibility="@{group1.visibility == View.VISIBLE? View.GONE : View.VISIBLE}"
                    app:constraint_referenced_ids="..." />

But I am getting a compilation error that says:

****/ data binding error ****msg:Could not resolve the two-way binding attribute 'visibility' on type 'android.support.constraint.Group'

What am I doing wrong?

like image 894
Rishabh876 Avatar asked Jan 03 '18 12:01

Rishabh876


1 Answers

I don't know why that error is happening, but this worked for me:

    group1.getVisibility() == View.VISIBLE

With that said, I couldn't get the constraint.Group to work as advertised. Also, to make them opposite each other, presumably you would need similar logic in group1's visibility, but that would be circular. Why not bind these to a ViewModel that controls when each should be visible?

like image 131
Alan Todtenkopf Avatar answered Dec 10 '22 12:12

Alan Todtenkopf