Skip to content
Sasa Sekulic edited this page Mar 30, 2016 · 9 revisions

When creating bindings, you can use different types, so that you make sure that the value isn't changed after you set it - or, on the contrary, is updated whenever you want. There are 5+1 different binding types (values in parentheses are the ones to be used in the XML layout files):

  1. Default (=) i.e. TwoWay (@=@) - The default binding type is the two-way continuous binding. Whenever either the source or the bound view are updated, the corresponding source/bound view will get updated.

  2. OneWay (@=) - One-way continuous updating is used when you want to update views that don't emit any values, like for example TextViews.

  3. OneWayOneTime (@-) - One-way one-time means that the bound view will be updated exactly once, when setting the Viewmodel. Make sure that the value is present there. You would probably use this for page titles or TextViews used as labels. Another use case is binding to methods, for example { Click @- ExampleClickListener } is used to set a click listener method.

  4. OneWayToSource (-@) - as OneWay, but pointing to another direction, from the view to the view model, inverting the data flow. You might use these for EditTexts, Switches, RadioButtons or any other type of input widget that you don't want to be set from code.

  5. OneWayToSourceOneTime (=@) - as OneWayOneTime but with the inverted flow, from widget to view model.