-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Android Studio 4.1 Development Essentials – Java Edition
By :

33.4 Implementing the View Model
With the user interface layout completed, the data model for the app needs to be created within the view model. Within the Project tool window, locate the MainViewModel.java file, double-click on it to load it into the code editor and modify the class so that it reads as follows:
package com.ebookfrenzy.viewmodeldemo.ui.main;
import androidx.lifecycle.ViewModel;
public class MainViewModel extends ViewModel {
private static final Float usd_to_eu_rate = 0.74F;
private String dollarText = "";
private Float result = 0F;
public void setAmount(String value) {
this.dollarText = value;
result = Float.parseFloat(dollarText)*usd_to_eu_rate;
}
...
Change the font size
Change margin width
Change background colour