GithubHelp home page GithubHelp logo

bambangherisetiawan / android-mvvm-databinding-formexample Goto Github PK

View Code? Open in Web Editor NEW

This project forked from alphamu/android-mvvm-databinding-formexample

0.0 2.0 0.0 147 KB

A demo of how to use Jetpack architecture and lifecycle component to implement a form. This includes validation and submit.

License: MIT License

Java 100.00%

android-mvvm-databinding-formexample's Introduction

android-MVVM-DataBinding-FormExample

A demo of how to use Jetpack architecture and lifecycle component to implement a form. This includes validation and submit.

Requires Android Studio 3.2 RC or Newer

Since this project uses Jetpack, you're going to need Android Studio 3.2 (currently in RC1) or newer.

Implementation notes

There are 2 methods used that can be found on branch method1 and method2. method1 pushed some of the form state and logic to the ViewModel where as with method2 the fields have their own model and the form has it's own model and the ViewModel only handles the bindings and exposing fields to the View.

Which method is better is up to you, while some argue that the ViewModel should contain the state of the screen/form (i.e. method1), others would argue that the ViewModel is more of an orchestration layer and should not contain anything to do with the state. Instead the ViewModel should only expose public properties and commands (i.e. method2).

Personally I think both are fine, but the actual answer may depends on the size of your app, and the need for reuse of the logic and models.

More

More discussion on this code can be found on my Medium blog post Android — Form input and validation using MVVM with DataBinding

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.