I have a working app with Hilt. Added the layout below but this specific spinner view is having problems while the rest is working fine. The spinner data binding itself is working and entries being populated, but for some reason this part cannot find the view id tags_spinner.
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:onClick="#{(view) -> viewModel.process(tags_spinner)}"/>
The unusual thing is the other image button can find its target view just fine.
`<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:onClick="#{(view) -> viewModel.process(tag)}"/>`
My app is running on these versions:
hilt_version = '2.40.5'
lifecycle_version = '2.4.1'
kapt_version = '1.6.20-RC'
Layout code below.
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="viewModel"
type="com.base.BaseActivityViewModel" />
<variable
name="adapter"
type="android.widget.ArrayAdapter" />
<import type="android.view.View"/>
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="#+id/trackerNameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Page Name"
android:text="#={viewModel.page.pageName}"
app:layout_constraintTop_toTopOf="parent"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/trackerNameEditText">
<Spinner
android:id="#+id/tags_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:listitem="#android:layout/simple_spinner_dropdown_item"
android:setAdapter="#{adapter}"
android:entries="#{viewModel.tagsList}"/>
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:onClick="#{(view) -> viewModel.process(tags_spinner)}"/>
<EditText
android:id="#+id/tag"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:hint="New Tag"/>
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:onClick="#{(view) -> viewModel.process(tag)}"/>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
Found that it is a bug which I haven't fully understood yet, it causes the problem when assigning view ids containing an undescrore _. Simply changing my assignment to "#+id/tagsSpinner" fixed the problem.
Related
I am fairly new with Android Studio and have ran into a problem that I have not come across before. Within an xml layout I am having a ParseError on line 22, which is the layout_height for the ScrollView. The error says Resource Compilation Failed. I have checked any posts that are even remotely close to this issue and have had no luck so far. Any tips would be appreciated.
<?xml version="1.0" encoding="utf-8"?>
<layout android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SizeFragment"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="orderModel"
type="com.example.pizzaorder.model.OrderModel" />
<variable
name="sizeFragment"
type="com.example.pizzaorder.SizeFragment" />
</data>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.textview.MaterialTextView
android:id="#+id/welcome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="120dp"
android:gravity="center"
android:text="#string/welcome"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/twelve_inch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginTop="72dp"
android:layout_marginEnd="32dp"
android:onClick="#{() -> sizeFragment.moveToBase(12)}"
android:text="#string/size_twelve"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/welcome" />
<Button
android:id="#+id/eighteen_inch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="32dp"
android:onClick="#{() -> sizeFragment.moveToBase(18)}"
android:text="#string/size_eighteen"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/twelve_inch" />
<Button
android:id="#+id/twenty_four_inch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="32dp"
android:onClick="#{() -> sizeFragment.moveToBase(24)}"
android:text="#string/size_twenty_four"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/eighteen_inch" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
</layout>
As per the comment, remove height, width, and context from the layout tag and put it in the ScrollView tag. The layout tag does not support these attributes, it is only used to create the data binding and to hold the variables.
So I have build a login layout and expect to have a button at the bottom of the screen.
The layout of the login is defined as below:
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/black">
<include
android:id="#+id/login_button"
layout="#layout/widget_large_button"
bind:buttonTitle="#{#string/login}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
Unfortunately, the button remain on top and I can't figure out why
Below is the code of the button
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable name="buttonTitle" type="String"/>
</data>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="25dp"
android:layout_marginEnd="25dp"
android:layout_marginBottom="16dp"
android:background="#drawable/stripe_backgound_05"
android:clickable="false"
android:focusable="false"
android:letterSpacing="0.5"
android:paddingTop="25dp"
android:paddingBottom="25dp"
android:text="#{buttonTitle}"
android:textAllCaps="true"
android:textColor="#color/gainsboro_05"
android:textSize="16sp"/>
</FrameLayout>
</layout>
I am using include because this button will be used at different place and I do not want to redo the code every single time
With <include> tags, all layout_ parameters are ignored unless you specify android:layout_width and android:layout_height. So add them to your include tag:
<include
android:layout_width="match_parent"
android:layout_height="wrap_content"
... />
I try setting value to include layout.
I wrapped the root layout to tag and passed using app:headerTitle.
But I got this error
AAPT: C:\Users\ckdrb\Desktop\EMOPlayer\app\build\intermediates\incremental\mergeDebugResources\stripped.dir\layout\activity_equalizer.xml:11: error: attribute headerTitle (aka com.jakchang.emo:headerTitle) not found.
error: failed linking file resources.
I don't understand what's wrong, Because I followed so many examples.
equalizer.xml
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/player_background_theme"
android:orientation="vertical">
<include
android:id="#+id/appbar"
layout="#layout/layout_part_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:headerTitle="bas123"/>
</LinearLayout>
</layout>
layout_part_appbar.xml
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="headerTitle"
type="String" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/loginHeaderLayout"
android:layout_width="match_parent"
android:layout_height="56dp">
<Button
android:id="#+id/backButton"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginStart="5dp"
android:background="#drawable/back_arrow_black"
app:backgroundTint="#null"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/headerTitleText"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:textAlignment="center"
android:textSize="#dimen/appbar_title_text_size"
android:textStyle="bold"
android:textColor="#color/colorBlack"
android:layout_marginStart="10dp"
android:text="#{headerTitle}"
app:layout_constrainedWidth="true"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/backButton"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
To pass the value using data binding you need to set it as below
app:headerTitle="#{`bas123`}"
In the data section, you need to use fully qualified path or import the class, like in Java.
Using full path:
<data>
<variable
name="headerTitle"
type="java.lang.String" />
</data>
Using import:
<data>
<import type="java.lang.String"/>
<variable
name="headerTitle"
type="String" />
</data>
I have achieved this via code. First remove app:headerTitle="bas123" declared inside equalizer.xml. Then in fragment or activity set data to variable headerTitle. Look below code:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val binding = DataBindingUtil.setContentView<EqualizerBinding>
(this,R.layout.equalizer)
binding.appbar.headerTitle = "My Header"
}
Like app:headerTitle="#{#string/app_name}" in equalizer.xml file
First of all I have deep search for that and I didn't find any related topic or solution :(
I have created a library project and import it as a library in another project, this library in all of its views use Android dataBinding, I need to override a xml view or portion of it(say include) in my project
as follow :
product_details_quantity_layout.xml in Library
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/cl_quantity"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/dim_product_details_sc_quantity_view_mrgn_top"
android:layout_marginBottom="#dimen/dim_product_details_sc_quantity_view_mrgn_bottom"
android:background="#drawable/product_quantity_bg"
android:gravity="center"
android:layoutDirection="ltr"
android:paddingStart="#dimen/dim_product_details_sc_quantity_view_padding_start"
android:paddingTop="#dimen/dim_product_details_sc_quantity_view_padding_top"
android:paddingEnd="#dimen/dim_product_details_sc_quantity_view_padding_start"
android:paddingBottom="#dimen/dim_product_details_sc_quantity_view_padding_bottom"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.42">
<ImageView
android:id="#+id/iv_decrement"
multipleClick="#{true}"
android:layout_width="0dp"
android:layout_height="0dp"
android:onClick="#{decreaseBtnClick}"
android:src="#drawable/ic_minus"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="1:1.4"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.15" />
<ImageView
android:id="#+id/iv_increment"
multipleClick="#{true}"
android:layout_width="0dp"
android:layout_height="0dp"
android:onClick="#{increaseBtnClick}"
android:src="#drawable/ic_add"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="1:1.4"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.15" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#{productQty}"
android:textAlignment="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#id/iv_increment"
app:layout_constraintStart_toEndOf="#id/iv_decrement"
app:layout_constraintTop_toTopOf="parent"
tools:text="1" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<data>
<import type="android.view.View" />
<variable
name="productQty"
type="String" />
<variable
name="increaseBtnClick"
type="android.view.View.OnClickListener" />
<variable
name="decreaseBtnClick"
type="android.view.View.OnClickListener" />
</data>
</layout>
And in my project
product_details_quantity_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".ui.view.product_details.ProductDetailsActivity"
>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/cl_quantity"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:layoutDirection="ltr"
android:paddingStart="#dimen/dim_product_details_sc_quantity_view_padding_start"
android:paddingTop="#dimen/dim_product_details_sc_quantity_view_padding_top"
android:paddingEnd="#dimen/dim_product_details_sc_quantity_view_padding_start"
android:paddingBottom="#dimen/dim_product_details_sc_quantity_view_padding_bottom"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.42">
<ImageView
android:id="#+id/iv_decrement"
multipleClick="#{true}"
android:layout_width="0dp"
android:layout_height="0dp"
android:onClick="#{decreaseBtnClick}"
android:src="#drawable/ic_minuse_circle"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.23" />
<ImageView
android:id="#+id/iv_increment"
multipleClick="#{true}"
android:layout_width="0dp"
android:layout_height="0dp"
android:onClick="#{increaseBtnClick}"
android:src="#drawable/ic_add_circle"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.23" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#{productQty}"
android:textAlignment="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#id/iv_increment"
app:layout_constraintStart_toEndOf="#id/iv_decrement"
app:layout_constraintTop_toTopOf="parent"
tools:text="1" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<data >
<import type="android.view.View" />
<variable
name="productQty"
type="String" />
<variable
name="increaseBtnClick"
type="android.view.View.OnClickListener" />
<variable
name="decreaseBtnClick"
type="android.view.View.OnClickListener" />
</data>
</layout>
In this I got exception class cast exception, it can't cast the generated databinding class from child to the dataBinding in Parent
so I updated the tag in my project xml file to
after that it work fine and inflate the new view, but when generating new APK it give duplicated class error that the found twice in parent and child projects
so dears any help in this case will be highly appreciated.
Update
This my Include tag in the full xml file in parent
<include
android:id="#+id/cl_quantity"
layout="#layout/product_details_quantity_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:decreaseBtnClick="#{()->viewModel.onDecreaseQty()}"
app:increaseBtnClick="#{()->viewModel.onIncreaseQty()}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:productQty="#{String.valueOf(viewModel.productQty)}" />
Second Update Adding Import
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".ui.view.product_details.ProductDetailsActivity"
>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/cl_quantity"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:layoutDirection="ltr"
android:paddingStart="#dimen/dim_product_details_sc_quantity_view_padding_start"
android:paddingTop="#dimen/dim_product_details_sc_quantity_view_padding_top"
android:paddingEnd="#dimen/dim_product_details_sc_quantity_view_padding_start"
android:paddingBottom="#dimen/dim_product_details_sc_quantity_view_padding_bottom"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.42">
<ImageView
android:id="#+id/iv_decrement"
multipleClick="#{true}"
android:layout_width="0dp"
android:layout_height="0dp"
android:onClick="#{decreaseBtnClick}"
android:src="#drawable/ic_minuse_circle"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.23" />
<ImageView
android:id="#+id/iv_increment"
multipleClick="#{true}"
android:layout_width="0dp"
android:layout_height="0dp"
android:onClick="#{increaseBtnClick}"
android:src="#drawable/ic_add_circle"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.23" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#{productQty}"
android:textAlignment="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#id/iv_increment"
app:layout_constraintStart_toEndOf="#id/iv_decrement"
app:layout_constraintTop_toTopOf="parent"
tools:text="1" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<data >
<import type="***.databinding.ProductDetailsQuantityLayoutBinding"/>
<import type="android.view.View" />
<variable
name="productQty"
type="String" />
<variable
name="increaseBtnClick"
type="android.view.View.OnClickListener" />
<variable
name="decreaseBtnClick"
type="android.view.View.OnClickListener" />
</data>
</layout>
Using the include tag, you can pass variables.
<include android:id="#+id/secondary"
layout="#layout/data_binding_included_secondary_layout"
bind:secondaryUser="#{mainUser}"/>
Ref:
https://medium.com/#elia.maracani/android-data-binding-passing-a-variable-to-an-include-d-layout-3567099b58f
So if you have an include tag in your Library module, then override that xml file in your resources, you may be able to change it.
Ref:
Override resources in library android
Alternatively, you can programmattically add a view into your XML, it should work if you use the correct viewbing tags:
Ref:
Programmatically adding a layout + children
You can use class attribute to avoid cast exception.
https://developer.android.com/topic/libraries/data-binding/generated-binding#custom_binding_class_names
However, It seems the binding class is still from library project class.
So, we can't override binding behavior. we can't add|remove binding elements from base library project xml.
we can customize element only that area unrelated to data binding.
I have a problem with databinding. In the documentation, it said we can use include tag to host a custom layout and passing binding variable to it. When I tryout on 4.1.2 phone and emulator, the data not seems to bind but only bind the main layout fields.
This is my code of the main layout:
<layout>
<data>
<variable
name="Job"
type="nz.co.certifi.CERTIFI.Model.JobModel" />
</data>
<ScrollView
android:background="#color/TransparentColor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/scrollView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="false"
android:layout_alignParentEnd="false"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true">
<RelativeLayout
android:background="#color/TransparentColor"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
app:Job="#{Job}"
android:id="#+id/layoutCertification"
layout="#layout/view_certification_control"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"/>
This is the layoutCertification:
<layout>
<data>
<variable
name="Job"
type="nz.co.certifi.CERTIFI.Model.JobModel" />
<variable
name="Form"
type="nz.co.certifi.CERTIFI.Model.FormROIModel" />
</data>
<nz.co.certifi.CERTIFI.Control.EditTextWithModel
xmlns:sparkNS="http://schemas.android.com/apk/res/nz.co.certifi.CERTIFI"
sparkNS:modelProperty="CertificateId"
sparkNS:modelType="JobModel"
sparkNS:validationType="required_only"
android:contentDescription="Job: Form Certificate Id"
sparkNS:errorRequiredMessage="#string/error_reference_no_required"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="#string/activity_roi_step_one_hint_reference_no"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#{Job == null? Form.certificateId : Job.certificateId}"
android:textStyle="bold"
android:id="#+id/txtReferenceNo"
android:layout_alignParentTop="false"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toLeftOf="#+id/btnReference"
android:layout_toStartOf="#+id/btnReference"
android:layout_centerVertical="true" />
Yes it does. http://developer.android.com/tools/data-binding/guide.html#includes
Main layout
<data>
<variable
name="plu"
type="org.test.test.viewmodels.PluDetailViewModel" />
</data>
.
.
.
<include
layout="#layout/keypad_pludetail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
bind:plu="#{plu}"
/>
Included layout
<data>
<variable
name="plu"
type="org.test.test.viewmodels.PluDetailViewModel" />
</data>
.
.
.
<Button
android:id="#+id/keypad_accept"
style="#style/KeyPadButton"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="#string/keypad_accept"
android:enabled="#{plu.isOK}"
android:onClick="#{plu.confirm}"
/>
In fragment
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_plu_details, container, false);
binding.setPlu(pluDetailViewModel);
binding.executePendingBindings();