The problem is that the included layout is not considered a data-bound layout. To make it act as a unit, you need to pass a variable:
buttons.xml:
<layout xmlns:andr...> <data> <variable name="foo" type="int"/> </data> <Button android:id="@+id/button" ...." />
main.xml:
<layout xmlns:andr... ... <include layout="@layout/buttons" android:id="@+id/buttons" app:foo="@{1}"/> ....
Then you can access the buttons indirectly through the button field:
MainBinding binding = MainBinding.inflate(getLayoutInflater()); binding.buttons.button
Starting with 1.0-rc4 (just released), you no longer need a variable. You can simplify this to:
buttons.xml:
<layout xmlns:andr...> <Button android:id="@+id/button" ...." />
main.xml:
<layout xmlns:andr... ... <include layout="@layout/buttons" android:id="@+id/buttons"/> ....
George Mount Oct 05 '15 at 21:59 2015-10-05 21:59
source share