Android MVVM Design Pattern Examples

2019-01-16 00:19发布

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?

14条回答
淡お忘
2楼-- · 2019-01-16 01:03

There are plenty of examples for MVVM framework in github. I recommend using DroidWizard

DroidWizard does its own coupling between view and view model and the framework is slightly different from mvvm.

ModelEngine ViewModel View instean of Model ViewModel View

查看更多
【Aperson】
3楼-- · 2019-01-16 01:03

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.

查看更多
时光不老,我们不散
4楼-- · 2019-01-16 01:04

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

查看更多
Summer. ? 凉城
5楼-- · 2019-01-16 01:05

There is now an Official Android Data Binding Plugin although its still in beta at the moment. Work is also being done to add tooling support for the binding syntax in the beta version of Android Studio.

See below for more information

https://developer.android.com/tools/data-binding/guide.html

查看更多
啃猪蹄的小仙女
6楼-- · 2019-01-16 01:05

Great! Articals by @Florina Muntenescu

The Model-View-ViewModel Pattern

The main players in the MVVM pattern are:

  • The View — that informs the ViewModel about the user’s actions
  • The ViewModel — exposes streams of data relevant to the View
  • The DataModel — abstracts the data source. The ViewModel works with the DataModel to get and save the data.

Example of MVVM Architecture:

https://github.com/erikcaffrey/People-MVVM

https://github.com/googlesamples/android-architecture/tree/todo-mvvm-databinding/

https://github.com/iammert/Android-MVVM-Architecture

https://github.com/segunfamisa/android-mvvm-sample

https://github.com/manas-chaudhari/android-mvvm

查看更多
贼婆χ
7楼-- · 2019-01-16 01:07

A few years ago I also do some WPF&WP development,Prism & MVVM Light Toolkit is commonly use to build WP App,it is perfect for windows phone application architecture I think ! so I use my previous experience of WP development then imitate to create Android MVVM Light Toolkit(A toolkit help to build Android MVVM Application,We have more attributes for Data Binding of View(like Uri for ImageView) ,we create some command for deal with event( like click of Button),also have a global message pipe to communicate with other ViewModel).

GitHub:Android MVVM Light Toolkit, there are samples for reference.

Architecture: http://upload-images.jianshu.io/upload_images/966283-78b410b9af8b18fa.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240

hope to help you!

查看更多
登录 后发表回答