Architecture -- Data Binding Library

简介: 1). 简介Data Binding Library是一个支持库,允许在布局文件中绑定数据源。最小支持API为14,gradle插件最小为1.5.0。示例2).
1). 简介

Data Binding Library是一个支持库,允许在布局文件中绑定数据源。最小支持API为14,gradle插件最小为1.5.0。
示例

2). 配置
  • app/build.gradle
android {
    ...
    dataBinding {
        enabled = true
    }
}
3). 布局绑定表达式
<?xml version="1.0" encoding="utf-8"?>
<!--使用DataBinding时最外层包裹的内容-->
<layout xmlns:android="http://schemas.android.com/apk/res/android">
  <!--数据节点-->
  <data>
    <!--变量-->
    <variable
        name="user"
        type="com.mazaiting.jetpack.architecture.bean.User"/>
    <variable
        name="presenter"
        type="com.mazaiting.jetpack.architecture.expression.ExpressionPresenter"/>
  </data>

  <LinearLayout
      android:orientation="vertical"
      android:layout_width="match_parent"
      android:layout_height="match_parent">
    <TextView
        android:text="@{user.firstName}"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    <TextView
        android:text="@{user.lastName}"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    <TextView
        android:text="@{String.valueOf(user.index + 1)}"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    <TextView
        android:text="@{user.display ?? user.lastName}"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    <Button
        android:text="监听"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="@{(view) -> presenter.show(view, user) }"
        />
    <Button
        android:text="引用"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="@{ presenter::onClickShow }"
        />
    <Button
        android:text="修改FirstName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="onChangeFirstName"
        />
  </LinearLayout>

</layout>
4). Observable UI
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
  <data>
    <!--<variable-->
        <!--name="user"-->
        <!--type="com.mazaiting.jetpack.architecture.bean.ObservableUser"/>-->
    <variable
        name="user"
        type="com.mazaiting.jetpack.architecture.bean.BaseObservableUser"/>
  </data>
  <LinearLayout
      android:orientation="vertical"
      android:layout_width="match_parent"
      android:layout_height="wrap_content">
    <TextView
        android:text="@{ user.firstName }"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
    <TextView
        android:text="@{ user.lastName }"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
    <TextView
        android:text="@{ String.valueOf(user.age)}"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
    <Button
        android:text="修改FirstName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:onClick="onChangeFirstName"
        />
  </LinearLayout>
</layout>
5). 效果演示
img_75d080135951f2b9b791b44a25f6080f.gif
效果.gif

img_8a9d041039891608727047980cb89f10.png
打印结果.png
6). 代码下载
7). 原文地址
目录
相关文章
|
10月前
target overrides the `ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES` build setting defined in `Pods/Target S
target overrides the `ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES` build setting defined in `Pods/Target S
149 0
dyld Library not loaded Reason image not found 问题解决
添加第三方框架,然后启动app的时候会,提示dyld: Library not loaded: Reason: image not found 网上大部分的做法都是把Build Phases 里对应framework后边的选项修改成为Optional,但这个是治标不治本,还是没法解决问题
229 0
|
Shell
Detected problems with app native libraries (please consult log for detail): lib.so: text relocation
Detected problems with app native libraries (please consult log for detail): lib.so: text relocation
195 0
|
Java Shell PHP
Guidelines for Function Compute Development - Use Fun Local for Local Running and Debugging
Preface The following key concepts are involved in this document: Function Compute: an event-driven service that allows you to focus on writing and .
1806 0
LD_LIBRARY_PATH shouldn&#39;t contain the current directory when building glibc. Please change the envir
执行# ./glibc-2.14/configure 出现以下错误: checking LD_LIBRARY_PATH variable... contains current directory configure: error: *** LD_LIBRARY_PATH ...
2048 0
|
JavaScript Java Linux
Installing a Dependency Library for Function Compute
In common programming practice, projects, libraries, and system environments must be installed and configured in synergy.
14338 0
|
数据库 数据库管理 缓存
Architecture -- Room
1). 简介 Room persistence库为SQLite提供了一个抽象层,以便在利用SQLite的全部功能的同时实现更强大的数据库访问。 该库可帮助您在运行应用程序的设备上创建应用程序数据的缓存。
915 0