Android MVVM Design Pattern Examples

后端 未结 14 1223
逝去的感伤
逝去的感伤 2020-12-07 07:09

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 k

相关标签:
14条回答
  • 2020-12-07 07:41

    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

    0 讨论(0)
  • 2020-12-07 07:42

    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

    0 讨论(0)
  • 2020-12-07 07:46

    Recently I have implemented the MVVM pattern for building an Android app with Data Binding Library. Here you can read the detailed review of the work I have done and the code fragments: http://cases.azoft.com/mvvm-android-data-binding/

    To learn more about the topic, you can also have a look at these app samples: https://github.com/ivacf/archi

    There are visual examples of work done with the search and list screen.

    0 讨论(0)
  • 2020-12-07 07:46

    I found this Writing Testable Android MVVM App series written about MVVM using Android Data Binding library is really nice. In the series he explained from simple example to recyclerview, and there are tests as well.

    You can maybe try the mv2m library, too.

    0 讨论(0)
  • 2020-12-07 07:49

    There is one project called MVVMCross.

    It's free, open-source and well designed MVVM framework, developed by Stuart Lodge.

    He implemented binding for Android and iPhone, so now MVVM is applicable to all of these platforms too.

    For me it is one of the best MVVM frameworks - it really shows the power of MVVM. With it you can write one code (model and viewmodel layers) for different platforms (WP7, Android, iPhone, WinRT) and just change application UI (view layer).

    0 讨论(0)
  • 2020-12-07 07:51

    https://github.com/MindorksOpenSource/android-mvvm-architecture

    Android MVVM Architecture: Sample App

    This repository contains a detailed sample app that implements MVVM architecture using Dagger2, Room, RxJava, FastAndroidNetworking, PlaceHolderView and AndroidDebugDatabase

    The app has following packages:

    data: It contains all the data accessing and manipulating components.
    di: Dependency providing classes using Dagger2.
    ui: View classes along with their corresponding ViewModel.
    utils: Utility classes.
    
    0 讨论(0)
提交回复
热议问题