43.8 Adding the Conversion Method
When the Convert button is clicked, it is going to call a method on the ViewModel to perform the conversion calculation and place the euro value in the result LiveData variable. Add this method now within the MainViewModel.kt file:
.
.
class MainViewModel : ViewModel() {
private val usd_to_eu_rate = 0.74f
public var dollarValue: MutableLiveData<String> = MutableLiveData()
public var result: MutableLiveData<Float> = MutableLiveData()
fun convertValue() {
dollarValue.let {
if (!it.value.equals("")) {
result.value = it.value?.toFloat()?.times(usd_to_eu_rate)
...