Updating the SpendingStats class

You've already created the SpendingStats class and bound it to your layout, but it won't ever have any data in it because it's never actually created, and the ObservableField<SpendingStats> field in the AllowanceOverviewPresenter is never populated. There's a good reason for that--the stats take time to calculate. Even if we had a database to do the heavy lifting, there is potentially a substantial overhead to calculate these three numbers before you can put them on the screen, while you can directly invoke the Allowance.getTotalSpent() method as part of your layout XML that will block the main thread for the entire time it took to calculate that number. That's not a good idea, as that time delay can quickly ...

Get Hands-On Android UI Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.