0

So the problem space is pretty simple.

I have a layout. Let's call it fragment1.xml and it looks like this.

<?xml version="1.0" encoding="utf-8"?>
<layout>
    <data>
        <variable
            name="viewModel"
            type="SomeViewModel" />
    </data>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <include
            android:id="@+id/include_some_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            layout="@layout/layout_consent_checkbox"
            app:checkedData="@{viewModel.checkedData}" />
    </LinearLayout>
</layout>

And let layout file layout_consent_checkbox.xml be this.

<?xml version="1.0" encoding="utf-8"?>
<layout>
    <data>
        <variable
            name="checkedData"
            type="Boolean" />
    </data>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <CheckBox
            android:id="@+id/cb_some_data"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:checked="@={checkedData}"
            android:text="Plis check this?"/>
    </LinearLayout>
</layout>

Now according to my knowledge, this should work. checkedData in SomeViewModel should be updating the Boolean value, based on the status change of the CheckBox. But it isn't getting updated. Please have a look and update me on what I'm doing wrong. Thanks!

capt.swag
  • 10,335
  • 2
  • 41
  • 41
  • is this different than https://stackoverflow.com/questions/32947440/android-data-binding-using-include-tag – a_local_nobody May 24 '22 at 13:02
  • Not really, what I'm doing is two-way databinding. I am able to do proper one-way data binding, but not two-way. Something is missing from my code. – capt.swag May 24 '22 at 13:13
  • that's fine, i remember using something like the link i've posted but i think i just needed something simpler, instead of using multiple linear layouts you could consider creating custom views for these includes and just using them all in a constraint layout instead, having all these nested linear layouts isn't very good for performance most likely – a_local_nobody May 24 '22 at 13:16

0 Answers0