41.2 Adding LiveData to the ViewModel
Launch Android Studio, open the ViewModelDemo project created in the previous chapter and open the MainViewModel.kt file which should currently read as follows:
package com.ebookfrenzy.viewmodeldemo.ui.main
import androidx.lifecycle.ViewModel
class MainViewModel : ViewModel() {
private val rate = 0.74f
private var dollarText = ""
private var result: Float = 0f
fun setAmount(value: String) {
this.dollarText = value
result = value.toFloat() * rate
}
fun getResult(): Float {
return result
}
}
The objective of this stage in the chapter is...