Data Binding for Fun and Profit

@colinmlee

Who Are You?

Colin Lee

Android Software Engineer

@ Vidku

 

Twitter: @colinmlee

Vidku: @colin

Slides!

https://slides.com/colinlee/deck

All examples are at http://github.com/colintheshots

Android Dev Summit Talk

https://www.youtube.com/watch?v=NBbeQMOcnZ0

What is Data Binding?

Data binding provides a more expressive means of binding models to views using XML and generated code.

Advantages

  • Removes View code from Activities & Fragments
  • In the support library back to API 7
  • Excellent performance
  • XML layouts become single source of truth
  • Provides some null safety
  • Enables MVVM pattern
  • Eliminate boilerplate

Disadvantages

  • IDE support is not all there yet
  • Known bugs exist
  • Still in beta

Performance

  • Generated code, not reflection
  • Fewer traversals than separate findViewById() calls
  • Expressions cached between views
  • View changes are batched

Slide Credit: Jacob Tabak

Early Competitors

  • Kotlin Plugin
  • Holdr
  • Android Annotations
  • RoboGuice
  • Butterknife

Cool Places to Use

  • RecyclerViews
  • Fonts
  • View Listeners
  • ImageViews
  • Animations

Observable Fields

Updating a POJO does not update the view.

 

Use ObservableFields to

track updated values.

MVVM

Model

View

ViewModel

Model

Contains your raw data.

View

Provides formatted output to the user.

ViewModel

Formats your data for the view to output.

Code Example

Questions?

Please take a moment to fill out
the class feedback form via the
app.

 

 

Data Binding for Fun and Profit

By Colin Lee

Data Binding for Fun and Profit

  • 784