Tag Archives: Data Binding

Guessing Game – Play the game

In this chapter of the Guessing Game tutorial we are going to implement the core part, which is how we can play the game. For this, we are going to create one more ViewModel. This ViewModel will contain the business logic about the game.

In the very last chapter (Guessing Game – ViewModel), we have implement a ViewModel class already, which is responsible to change the username, and store it indside of a LiveData.

First, we are going to create an enum. This enum will hold the 4 states of the game. Then, we gonna start the implementation of the GameViewModel, which will contain the business logic. It means, here we gonna generate the random numbe to guess, then compare this number to the number of the guess, show the result and start a new game. Inside of this ViewModel we gonna implement two more methods, which will help us to show and hide the soft keyboard after every guess.

So, let’s start coding! 😎

Continue reading Guessing Game – Play the game

Follow and like us:

Guessing Game – ViewModel

In this chapter of the Guessing Game tutorial we are going to implement the first ViewModel, which will be a helper to change in real time the username.

In the very last chapter we have implemented the Navigation Component. This Jetpack library is responsible for the navigation inside of the app.

In our case, we have implemented 2 destinations. The first is the GameFragment, the second is the bottom sheet dialog. We can open it by tapping on the TextView of the username, or by clicking on the pen icon. After that, we can write our username inside of the EditText, but still it won’t be changed in the app.

We are going to implement this functionality by using a ViewModel and a LiveData. This LiveData will hold the username, what we will bind to the TextView inside of the GameFragment using Data Binding with layout variables and layout expressions.

So, let’s start coding. 😎

Continue reading Guessing Game – ViewModel

Follow and like us:

Guessing Game – Navigation Component

In this chapter of the Guessing Game tutorial we are going to implement the Jetpack Navigation Component library to navigate between the fragments.

In our case we have only 2 fragments. First, it will help us to show the GameFragment at startup. Then, when we want to set our username, it will open up the ChangePlayerDialogFragment also, which is inherited from the BottomSheetDialogFragment class.

Continue reading Guessing Game – Navigation Component

Follow and like us:

Guessing Game – Preparation

In this chapter of the Guessing Game tutorial we are going to talk about the preparation of the game. It means, we are going to build up the user interfaces, then we are going to add the needed dependencies and we gonna enable the Data Binding as well.

After that, we are going ot create the navigation graph. Finally, we gonna show you how you can transform the original layout to use Data Binding. So, let’s start coding. 😎

Continue reading Guessing Game – Preparation

Follow and like us:

Guessing Game – Introduction

In this tutorial, we are going to build up a simple guessing game. First, a short introduction to the game. The essence of the game is to figure out a hidden, randomly generated number. This number is between 1 and 10. We have endless possibilities to try.

From Android development side, we are going to use in this tutorial 2 Jetpack libraries, which are the Data Binding and the Navigaion Component. Then, we will use the MVVM design pattern, together with LiveData and ViewModel.

In our app, we will have only one Activity. This activity will hold a fragment, where we will define the view of the game and from this fragment we can open a bottom sheet dialog also.

Continue reading Guessing Game – Introduction

Follow and like us:

Guessing Game – BindingAdapter

In this chapter of the Guessing Game tutorial we are going to implement some custom attributes using BindingAdapter to show the result on the screen.

It means, we are going to create a new file, a Binding Adapter, where we will define some methods. These methods will be responsible to tell for the user visually whether the number is smaller, larger or you could find the number to guess. 

In the very last chapter (Guessing Game – Play the game), we have implemented the main part of the game. It means, that the game works perfectly, you can play with it, but still we can’t see visually the result, only in the Logcat of Android Studio.

Continue reading Guessing Game – BindingAdapter

Follow and like us: