Looking at the final app screenshots of this codelab, we’ll notice that the price is actually displayed on each fragment (except the StartFragment) so the user knows the price as they create the order.
Press enter or click to view image in full size
We will update the price in ViewModel.
package ...
import ...
private const val PRICE_PER_CUPCAKE = 2.00
class OrderViewModel : ViewModel() { ...
Now that we have defined a price per cupcake, we will create a helper method to calculate the price. This method can be private because it's only used within this class.
Then we will run the app and if we select One Cupcake in the fragment, it will show the Subtotal 12.0. Now we will make a similar change for the pickup and summary fragments. In fragment_pickup.xml and fragment_summary.xml layouts, modify the text views to use the viewModelprice property as well.