Skip to content

Instantly share code, notes, and snippets.

@liangfeidotme
Last active April 15, 2019 13:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save liangfeidotme/cc5b3af06a2a71039f20 to your computer and use it in GitHub Desktop.
Save liangfeidotme/cc5b3af06a2a71039f20 to your computer and use it in GitHub Desktop.
Use Android Data Binding with include tag
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bind="http://schemas.android.com/apk/res-auto">
<data>
<import type="com.liangfeizc.databindingsamples.basic.User" />
<variable
name="user"
type="User" />
<variable
name="contact"
type="com.liangfeizc.databindingsamples.custombindings.Contact" />
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
layout="@layout/user"
bind:user="@{user}" />
<include
layout="@layout/contact"
bind:contact="@{contact}" />
</LinearLayout>
</layout>
@SaitejaP
Copy link

I cannot figure out how to set the binding when using <include ... />. I meant the java part of data binding. Can you help me please?

@thuytrinh
Copy link

It'd be great if u can show the included layout.

@mustafasevgi
Copy link

Please can you add contact.xml and user.xml?

@ameyab10
Copy link

ameyab10 commented Sep 3, 2016

I am trying the same thing but cant seem to nail it.

@Fatimamostafa
Copy link

This article shows a way to pass variables to an <include>'d layout.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment