For the More Curious: More About Data Binding

Complete coverage of data binding is outside the scope of this book. And yet, reader, we must nevertheless try.

Lambda expressions

You can write short callbacks directly in your layout file by using lambda expressions. These are simplified versions of Java’s lambda expressions:

        android:onClick="@{(view) -> viewModel.onButtonClick()}"
        tools:text="Sound name"/>

Like Java 8 lambda expressions, these are turned into implementations for the interface you use them for. (In this case, View.OnClickListener.) Unlike Java 8 lambda expressions, these expressions must use this exact ...

Get Android Programming: The Big Nerd Ranch Guide, 4th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.