how to do Data Binding in android studio

edited June 2023 in Android

First, add the data binding value True in Gradle .


dataBinding {
        enabled = true
    }


Then <Layout> </Layout> Attribute Add to the XML layout

<layout   xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"> 


  </layout>

data binding declear in the class in on create method

protected void onCreate(Bundle savedInstanceState) {





    val homeBinding: ActivityHomeBinding = DataBindingUtil.setContentView(this, R.layout.activity_home)

 binding.progressBarLayout.visibility = View.GONE   

}


Sign In or Register to comment.