This is my note for Udemy lesson: Advanced Android Bootcamp 2024.
1. Set up Data Binding
Please see my previous note.
2. Edit the xml File
<layout ...> <data> <variable name="student" type="com.xxx.xxx.Student" /> </data> <androidx.constraintlayout.widget.ConstraintLayout ...> ... <TextView ... android:text-"@{student.name}" /> ... </androidx.constraintlayout.widget.ConstraintLayout> </layout>
3. Pass the Object from Activity
private lateinit var binding: ActivityMainBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = DataBindingUtil.setContentView(this,R.layout.activity_main) binding.student = Student("Alex") }