nicolas asinovich
nicolas asinovich

Reputation: 3511

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?

Upvotes: 5

Views: 1590

Answers (2)

Tarık
Tarık

Reputation: 129

If the problem is that you cannot see <fragment android:id="@+id/map_fragment" object when you try binding.mapFragment, just change

<fragment to <androidx.fragment.app.FragmentContainerView

Upvotes: 0

nicolas asinovich
nicolas asinovich

Reputation: 3511

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>

Upvotes: 10

Related Questions