Bind ViewModel to a Fragment (Game)
We did most of the UI work here last chapter in Build Another Fragment (Game), so there’s less to worry about now. The first thing we need is to add a <variable> for GameViewModel called vm.
| <layout xmlns:android="http://schemas.android.com/apk/res/android" |
| xmlns:app="http://schemas.android.com/apk/res-auto" |
| xmlns:tools="http://schemas.android.com/tools"> |
| |
» | <data> |
» | <variable |
» | name="vm" |
» | type="dev.mfazio.pennydrop.viewmodels.GameViewModel" /> |
» | </data> |
| |
| <androidx.constraintlayout.widget.ConstraintLayout |
| android:layout_width="match_parent" |
| android:layout_height="match_parent" |
| android:animateLayoutChanges="true" |
| tools:context=".GameFragment"> |
| <!-- Previously created views ... |
Get Kotlin and Android Development featuring Jetpack now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.