Two Way DataBinding With Kotlin & Java In Android

Two Way Data Binding Android Teachers

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

MyTwoWayBinding.kt

Result GIF

Result Of Two Way Binding

Two Way Data Biding Android

5884total visits.

Related posts

3 Thoughts to “Two Way DataBinding With Kotlin & Java In Android”

  1. Dilavar

    Nice Tutorial, Keep it up

  2. Tarika Chawla

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

    1. Imtiyaz Khalani

      Hi Tarika .!
      Thanks for Comment but app:textChangedListener is right.
      Keep Commenting so we can improve things right.

Leave a Comment