1. Normal Data Binding for VO
package vo { [Bindable] public class Student { public var id:int; public var name:String; public var gender:String; public function Student(id:int, name:String, gender:String) { this.id = id; this.name = name; this.gender = gender; } } }
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"> <fx:Declarations> <!-- Place non-visual elements (e.g., services, value objects) here --> </fx:Declarations> <fx:Script> <![CDATA[ import mx.controls.Alert; import vo.Student; [Bindable] private var student:Student = new Student(1, "Davy", "Male"); private function handler(event:MouseEvent):void { student.id ++; } ]]> </fx:Script> <s:Button label="{student.id}" click="handler(event)"/> </s:Application>
Comment:
1) Every time we click the button, both the button label and the student.id will change accordingly.
2) If we leave out the [Bindable] annotation for student in Application domain, we will get a warning but it still works.
3) If we leave out the [Bindable] annotation for id in VO and we add this on var student, it will not work cause the id is not bindable.
2. Binding all properties for MXML
<fx:Metadata> [Bindable] </fx:Metadata>
Comment:
1) Why it doesn't work?
3. Binding Using ObjectProxy
1) Why using ObjectProxy?
We using ObjectProxy to monitor the properties changes in our custom VO.
In the previous charpter, we are using the custom event dispatched to monitor a specific attribute in our custom VO. But what if we want to monitor all the property changes in VO?
2) How to use ObjectProxy?
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" creationComplete="setWatcher(event);" minWidth="955" minHeight="600"> <fx:Declarations> <!-- Place non-visual elements (e.g., services, value objects) here --> </fx:Declarations> <fx:Script> <![CDATA[ import mx.controls.Alert; import mx.events.PropertyChangeEvent; import mx.utils.ObjectProxy; import vo.Student; private var student:Student = new Student(1, "Davy", "Male"); private var objectProxy:ObjectProxy; private function setWatcher(event:Event):void { objectProxy = new ObjectProxy(student); objectProxy.addEventListener(PropertyChangeEvent.PROPERTY_CHANGE, onChange); objectProxy.id = 2; objectProxy.name = "Clay"; objectProxy.gender = "Female"; } private function onChange(event:Event):void { idLabel.text = objectProxy.id.toString(); } ]]> </fx:Script> <s:Label id="idLabel"/> </s:Application>
package vo { public class Student { public var id:int; public var name:String; public var gender:String; public function Student(id:int, name:String, gender:String) { this.id = id; this.name = name; this.gender = gender; } } }
Comment:
1) Pay attention while changing the attribute, we are not changing that of VO's but changing that of ObjectProxy's.
2) It works the same as we add [Bindable] annotation to all attributes in Student/Vo.
相关推荐
Android Data Binding RecyclerView Using Recyclerview with the new Android Data Binding framework. ... dataBinding { enabled = true } Modify your layout Remember to use your classes and packages ;-).
DataBinding-ktx使声明数据绑定变得容易。 在这里。 数据绑定中的问题 忘记在DataBinding中调用setLifecycleOwner 。 在Activity和Fragment中声明binding变量的方式有所不同。 在活动中,可以使用by lazy声明...
:dna:Android DataBinding套件,用于通知MVVM架构上从Model层到UI层的数据更改。 Bindables:dna:Android DataBinding工具包,用于通知从模型层到UI层的数据更改。 该库提供了DataBinding的基类(BindingActivity,...
赠送jar包:cxf-rt-databinding-jaxb-3.0.1.jar; 赠送原API文档:cxf-rt-databinding-jaxb-3.0.1-javadoc.jar; 赠送源代码:cxf-rt-databinding-jaxb-3.0.1-sources.jar; 赠送Maven依赖信息文件:cxf-rt-...
DataBinding RecyclerViewAdapter 中文版 README Free from writing adapters! NO MORE CLASSES! Super simple RecyclerView adapter using Data Binding Technology, no longer need to write any adapter! You don...
Tarea2RecyclerView:使用DataBinding和callBack的Recycler视图
DataBinding中ViewStub例子
:dna: Android DataBinding工具包,用于通知数据从模型层到UI层的更改。 该库提供了DataBinding的基类(BindingActivity,BindingFragment,BindingViewModel), 并支持在没有可观察字段和LiveData的情况下通知...
即时天气 :sun_behind_cloud: 使用 MVVM 模式、Retrofit2、Dagger2、LiveData、ViewModel、Coroutines、Room、Navigation Components、Data Binding 和来自一些其他库实现的 Android 天气应用程序。...
高仿"掘金Android App": databinding kotlin rx 的优雅实践
关于Android的DataBinding技术分享文档,是私人文档。
DataBinding在recycleview中的使用,DataBinding在recycleview中的使用
Android Databinding 与 RecyclerView 完美结合。Android Databinding 与 RecyclerView 完美结合。
DataBinding的使用与原理
【Jetpack】DataBinding 架构组件 ② ( 字符串拼接函数 | 绑定点击事件函数 | DataBinding 布局中使用 import 标签导入 Java、Kotlin 类 ) https://hanshuliang.blog.csdn.net/article/details/129773150 一、...
关于Jquery扩张库DataBinding的一个更新的版本,比之前的版本增加了不少了功能
完整的android databinding例子, 里面包括了各种输入ui,switch, imageview, button事件, recyclerview的绑定应用及双向绑定. 对于初学者来讲非常简单易懂, 具体说明 ...
Android数据绑定扩展 一组启用了Android数据绑定的活动,片段等(也是Dagger变体)。 安装 要使用该库,请先使用... implementation( " org.mobiletoolkit.android.databinding:databinding:{RELEASE_TAG} " ) imp
DataBinding实现RecyclerView的Demo
Room、LiveData、ViewModel、Paging、DataBinding这些库怎么结合起来使用?怎样用AndroidX取代Support Library?传统MVP和基于Jetpack实现的MVVM有什么区别?这个App应该能给大家一点启发。欢迎star/fork。 分支含义...