Sign in Go Pro

Android Model-View-ViewModel Pattern

Add Save Functionality to the ViewModel

This lesson is for PRO members.

Upgrade today to get access to all the PRO lessons.

Unlock this lesson

Up next



In this lesson, we'll be updating the ViewModel to support saving a calculated tip by name. Through the process, you'll learn about computed properties with Kotlin and see first hand the value of good unit test coverage, to support code refactoring. We'll also learn about using Mockito to verify interactions with mock objects and how using a function within a function, can greatly simplify your test and convey intent.

Key concepts in this lesson that you will learn:

  • How to use Kotlin computed properties for the View
  • Refactoring with confidence, thanks to good test coverage
  • How to verify interactions with mock objects using Mockito
  • How to add a function within a function in Kotlin, to simplify them and convey intent.


Hi Eric, I'm getting this error not able to build project

import com.demo.android_samples.databinding.ContentMainBindingImpl;
cannot find symbol class ContentMainBindingImpl
A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution

when using val outputCheckAmount get() = getApplication().getString(R.string.dollar_amount, lastTipCalculated.checkAmount)

so when i change outputCheckAmount from val to var and remove get() this gets compiled but the output is not shown on UI.Can you please help to solve this issue ?

using version:
kapt "androidx.databinding:databinding-compiler:4.0.1"


Lessons in Android Model-View-ViewModel Pattern