Creating an Observable model

To get things started on this part of the project, you'll need a new model class to encapsulate the allowance and spending of the user. We'll call the new class Allowance, and build in some utility methods to fetch useful information (such as how much the user spent between two dates). Most importantly, this new model needs to tell us when it changes. This can technically be done in several ways: through an event-bus, or specialized listeners, but for this example, we'll go with an Observer pattern. To make this work, the Allowance class will extend from BaseObservable, a convenience class that is part of the data binding API. Whenever the Allowance class changes, it'll emit events notifying its observers of the ...

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.