Android Advanced Note 14:robobinding (Implementation of the data-bound Presentation model (MVVM) mode Android Open source framework)

Source: Internet
Author: User

1.RoboBinding

Robobinding is an Android open source framework that implements the data-bound Presentation model (MVVM) pattern. From a simple point of view, he removes unnecessary code such as Addxxlistener (), Findviewbyid (), even injectview like bufferknife do not need, because your code generally does not need to rely on these interface component information. The following is an example of the simplest ANDROIDMVVM.

(1) Layout layouts

<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Xmlns:bind= "Http://robobinding.org/android">    <TextViewBind:text= "{Hello}" />        ...    <ButtonAndroid:text= "Say Hello"Bind:onclick= "SayHello"/></LinearLayout>

(2) Presentation Model

1  Public classPresentationmodelextendsAbstractpresentationmodel {2     PrivateString name;3      PublicString Gethello () {4         returnName + ": Hello Android MVVM (Presentation Model)!";5     }6     ...7      Public voidSayHello () {8Firepropertychange ("Hello");9     }Ten}

(3) The activity binds layout to the corresponding presentation model

1  Public classMainactivityextendsActivity {2 @Override3     protected voidonCreate (Bundle savedinstancestate) {4         ...5Presentationmodel Presentationmodel =NewPresentationmodel ();6View Rootview = Binders.inflateandbindwithoutpreinitializingviews ( This, R.layout.activity_main, Presentationmodel);7 Setcontentview (rootview);8     }9}

This layout {Hello} is bound to Presentationmodel.hello, and the SayHello of layout is bound to the Presenationmodel.sayhello method. We don't need to define textview in layout, the button ID because we don't care, and it's not necessary. When we look further, we find that Presentationmodel is a pure POJO. This is why the software community, Martin Fowler, introduced the presenation model (MVVM) pattern in 2004. It is an upgrade of the MVC we are familiar with, which further decouples the interface state from the logic into the presentation model.

We can learn robobinding using the following few sample projects, they can all be directly imported into Android studio without additional configuration:

1.AndroidMVVM, the smallest robobinding use example.

2.Album sample, is the original example of Martin Fowler's presentation model model based on Robobinding's Android translation version.

3.Gallery, is used to display the various features of robobinding including fragment, Menu, Viewpager, etc.

The Chinese document address for the project is: http://robobinding.github.io/RoboBinding/index.zh.html

GitHub Address https://github.com/RoboBinding/RoboBinding

Android Advanced Note 14:robobinding (Implementation of the data-bound Presentation model (MVVM) mode Android Open source framework)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.