Two Way DataBinding With Kotlin & Java In Android

Two Way DataBinding With Kotlin & Java In Android

In previous post, I’ve explained Data Binding With Kotlin & Data Binding with Fragment  that example of one way data binding. You bind model and view will display data as per model values but suppose your data changes frequently then Two Way DataBinding will help you to update views when data update. BaseObservable class will help  to update views as well.

Let’s Take Example For Login Screen where we need to validate User id.
– User id length 8 digit

We have bind out Data Model or POJO class with XML in Data Binding With Kotlin Tutorial. Today we will learn how to bind event.Data Binding means you bind your model with XML and you will be free to set component value. This is part of best practices for android development.

Now It helps you to manage view/presenter separately but two-way binding comes in picture when your view required to bind some thing with your data/event.



Create Model

MyModel class

Create Layout

activity_two_way_binding Layout

Bind Model with Layout


Result GIF

Result Of Two Way Binding

Two Way Data Biding Android

3 thoughts on “Two Way DataBinding With Kotlin & Java In Android

  1. In the activity_two_way_binding Layout, For the EditText its supposed to be “app: addTextChangedListener” instead of “app:textChangedListener”

Leave a Comment