Android 如何将OnClickListener传递到包含的布局?
我需要将OnClickListener从父级传递到包含的布局 我有一个包含接受OnClickListener的视图的布局:Android 如何将OnClickListener传递到包含的布局?,android,android-databinding,Android,Android Databinding,我需要将OnClickListener从父级传递到包含的布局 我有一个包含接受OnClickListener的视图的布局: <?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:/
<?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">
<data>
<variable
name="clickListener"
type="android.view.View.OnClickListener" />
</data>
<include // I need to pass here
android:id="@+id/button_more"
layout="@layout/button_more"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
以及包含的布局(button_more.xml):
如何将OnClickListener传递到包含的布局?U可以通过以下方式将clickListener从父级传递到包含的布局:
<include layout="@layout/button_more"
app:listener="@{clickListener}"/>
<include layout="@layout/button_more"
app:listener="@{clickListener}"/>