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)