I currently do a lot of WPF development and have started creating some basic Android apps. When creating WPF apps I often use MVVM, normally using Prism, and would like to know if there are any examples of MVVM for the Android platform?
Model — View — ViewModel (MVVM) is the industry-recognized software architecture pattern that overcomes all drawbacks of MVP and MVC design patterns. MVVM suggests separating the data presentation logic(Views or UI) from the core business logic part of the application.
In Android, MVC refers to the default pattern where an Activity acts as a controller and XML files are views. MVVM treats both Activity classes and XML files as views, and ViewModel classes are where you write your business logic. It completely separates an app's UI from its logic.
MVVM stands for Model, View, ViewModel. Model: This holds the data of the application. It cannot directly talk to the View. Generally, it's recommended to expose the data to the ViewModel through Observables. View: It represents the UI of the application devoid of any Application Logic.
The ViewModel class is designed to store and manage UI-related data in a lifecycle conscious way. The ViewModel class allows data to survive configuration changes such as screen rotations.
I am the developer of Android-Binding. Like @Brentley said, it's a very new project but I do hope to get more buzz and experience so that it can be improved. Back to your question, I have written some simple introduction/tutorials on MVVM with android-binding:
Potential adopters please also register on the project discussion group.
I sometimes use ViewModels to translate from a pure Model to what the Model should be displayed as, but so much of the MVVM-isms come from the fact that you have this massive data binding engine built into the WPF framework. You probably won't find the exact experience of WPF + MVVM in the Android world, but you can take a lot of the good concepts and implement them (just without the automatic data binding stuff).
For one, just create ViewModels. You don't need a framework like Prism to create ViewModels. You don't have all the PropertyChanged notifications and stuff like that, but you can translate your data into information that can be better used by your UI which will clean up your code. A perfect example of this is something I did with a slider-heavy UI. Android's SeekBar is always zero based and works with integer values, so you can't bind to min, max, and increment values from your model. You can use a ViewModel to translate your min/max values into 0-based equivalents that your SeekBar can use...just an example. Same goes for displaying colors and sizes based on value ranges, etc. To me, that's what ViewModels are all about.
As far as DependencyInjection stuff, check out RoboGuice. I just started using this in one of my projects after seeing a presentation by its creator at a local Meetup, and it's probably just what you're looking for.
RoboGuice on Google Code
RoboGuice Google Group
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With