41.2 Adding LiveData to the ViewModel
Launch Android Studio, open the ViewModelDemo project created in the previous chapter and edit 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 usd_to_eu_rate = 0.74f
private var dollarText = ""
private var result: Float = 0f
fun setAmount(value: String) {
this.dollarText = value
result = value.toFloat() * usd_to_eu_rate
}
fun getResult(): Float? {
return result
}
}
The objective of this stage...