Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

msg:fragments do not support data binding expressions (in tag <fragment>) data binding error

I have a problem with data binding when I try to add visibility for tag fragment with map:

<layout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        >
    <data>
        <import type="android.view.View"/>
        <import type="xxx.xxx.MapContract.ViewModel"/>
        <variable
                name="vm"
                type="ViewModel"
                />
    </data>
    <FrameLayout
            xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            >
        <fragment
                android:id="@+id/map_fragment"
                class="com.google.android.gms.maps.SupportMapFragment"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:visibility="@{vm.showMap}" // here problem
                />

How can I solve this problem use data binding? Why fragments do not support data binding?

like image 800
nicolas asinovich Avatar asked Jan 26 '23 15:01

nicolas asinovich


1 Answers

I solve this issue just like this:

 <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:visibility="@{!vm.showMap}" // move here
            >
        <fragment
                android:id="@+id/map_fragment"
                class="com.google.android.gms.maps.SupportMapFragment"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                />
    </FrameLayout>
like image 192
nicolas asinovich Avatar answered Feb 04 '23 03:02

nicolas asinovich