Gitlab@Informatics

Skip to content
Snippets Groups Projects
Commit d7e4dec6 authored by 62160052's avatar 62160052
Browse files

Add data binding variables

parent 196cb3fd
Branches
No related tags found
No related merge requests found
...@@ -62,7 +62,9 @@ class GameFragment : Fragment() { ...@@ -62,7 +62,9 @@ class GameFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
binding.gameViewModel = viewModel
binding.maxNoOfWords = MAX_NO_OF_WORDS
// Setup a click listener for the Submit and Skip buttons. // Setup a click listener for the Submit and Skip buttons.
binding.submit.setOnClickListener { onSubmitWord() } binding.submit.setOnClickListener { onSubmitWord() }
binding.skip.setOnClickListener { onSkipWord() } binding.skip.setOnClickListener { onSkipWord() }
...@@ -81,6 +83,9 @@ class GameFragment : Fragment() { ...@@ -81,6 +83,9 @@ class GameFragment : Fragment() {
) { newScore -> ) { newScore ->
binding.score.text = getString(R.string.score, newScore) binding.score.text = getString(R.string.score, newScore)
} }
// Specify the fragment view as the lifecycle owner of the binding.
// This is used so that the binding can observe LiveData updates
binding.lifecycleOwner = viewLifecycleOwner
} }
/* /*
......
...@@ -19,7 +19,12 @@ ...@@ -19,7 +19,12 @@
xmlns:tools="http://schemas.android.com/tools"> xmlns:tools="http://schemas.android.com/tools">
<data> <data>
<variable
name="gameViewModel"
type="com.example.android.unscramble.ui.game.GameViewModel" />
<variable
name="maxNoOfWords"
type="int" />
</data> </data>
<ScrollView <ScrollView
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment