Build Another Fragment (Game)
Kotlin and Android Development featuring Jetpack — by Michael Fazio (20 / 125)
👈 Add Data Binding to the App | TOC | Summary and Next Steps 👉
We created GameFragment last chapter, but it still looks pretty sad, especially compared to the PickPlayersFragment. By the time we wrap up this chapter, we’ll have a screen that looks like the image shown.
The rest of this chapter will be spent in GameFragment, so I recommend going to navigation/nav_graph.xml and setting app:startDestination to @id/gameFragment. Then, we’ll start by enabling data binding for GameFragment.
Enable Data Binding for GameFragment
As we’re just turning on data binding in GameFragment right now, all we need to do in fragment_game.xml is add that generic <layout> tag plus an empty <ConstraintLayout>. While the <ConstraintLayout> isn’t critical for data binding, we’re going to be using it soon, so might as well add it now. Our bare-bones view’s XML will look like this:
<?xml version="1.0" encoding="utf-8"?>
<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">
…