Unable to find symbol FragmentBindingImpl with databinding bindingadapter android? - android

Below is my main layout where I have included another layout
<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="userName"
type="String" />
<variable
name="hasEnded"
type="Boolean" />
<variable
name="showLoader"
type="Boolean" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/parent_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/base_chat_background">
<com.commonui.AppBar
android:id="#+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#{userName}"
app:addWindowInsetPaddingTop="#{true}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="0dp"
android:layout_height="0dp"
android:clipToPadding="false"
android:paddingTop="16dp"
android:paddingBottom="70dp"
app:addWindowInsetPaddingBottom="#{true}"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/app_bar" />
<include
android:id="#+id/feedbackLayout"
visibleIf="#{hasEnded}"
layout="#layout/chat_feedback"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<ProgressBar
android:id="#+id/loader"
visibleIf="#{showLoader}"
android:layout_width="44dp"
android:layout_height="44dp"
android:layout_gravity="center"
android:layout_marginTop="16dp"
android:indeterminate="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/app_bar" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
I have an extension function with which I am handling the visibility of views in XML
#BindingAdapter("visibleIf")
fun setVisibleIf(view: View, visible: Boolean) {
view.visibility = if(visible) View.VISIBLE else View.GONE
}
When I add visibleIf="#{hasEnded}" to my included layout and build the project I get the error
error: cannot find symbol
import com.chat.databinding.FragmentPeerchatBindingImpl;
symbol: class FragmentChatBindingImpl
location: package com.chat.databinding
What could be the cause of it?

Apparently included layout doesn't support binding adapter for now
Alternative is to send your variable from main layout to included layout
We can use app:showFeedback="#{hasEnded}" here showFeedback is the binding variable defined in included layout. hasEnded is the variable defined in the main layout

Related

Hilt Data binding: One specific view is getting "Could not find identifier"

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.

Why is Android Studio ScrollView, having a resource compilation fail

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.

android binding value to include layout is failed,

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

Android XML Data Binding pass view by id

In order to show a BottomSheetBehavior i need to pass his view like below.
ViewUtil.kt class
fun showBottomSheet(view: View) {
val bottomSheetBehavior = BottomSheetBehavior.from(view)
if (bottomSheetBehavior.state == BottomSheetBehavior.STATE_COLLAPSED) {
bottomSheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED
} else {
bottomSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED
}
}
Fragment.kt
termsTitle.setOnClickListener {
showBottomSheet(tosLayoutBottomSheet)
}
bottom_sheet_tos.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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"
android:id="#+id/tosLayoutBottomSheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:behavior_hideable="true"
app:behavior_peekHeight="0dp"
app:layout_behavior="#string/bottom_sheet_behavior">
<!-- some stuff about terms of service -->
</androidx.constraintlayout.widget.ConstraintLayout>
fragment.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:ignore="MissingDefaultResource">
<data>
<import
alias="v"
type="android.view.View" />
<variable
name="fragmentViewModel"
type=".FragmentViewModel"/>
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/main_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background_main_page">
<TextView
android:id="#+id/terms_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginStart="24dp"
android:layout_marginBottom="8dp"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:text="#string/terms_of_service"
android:textColor="#color/colorGrey"
android:textSize="20sp"
android:textStyle="bold"
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>
</layout>
So, instead use onclicklistener from fragment I would like to do it from my xml and viewmodel like:
fragment.xml
<TextView
android:id="#+id/terms_title"
android:onClick="#{(v)-> fragmentViewModel.showBottomSheetFrag(tosLayoutBottomSheet)}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginStart="24dp"
android:layout_marginBottom="8dp"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:text="#string/terms_of_service"
android:textColor="#color/colorGrey"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent" />
I know the above approach not work because tosLayoutBottomSheet id is in another layout. How can I pass an id from a different layout ?
A bit late but you can add an import of R class in your xml file and then pass the view id with R.id.view_id
<import type="com.xxx.xxxx.R" />
then in you onclick
android:onClick="#{(v)->view.yourMethod(R.id.view_id)}"

How to override xml view (that use data Binding) from Library in my project (# Override_Views_Data_Binding_Android )

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.

Categories

Resources