android.DataBindingUtil
import android.databinding.DataBindingUtil
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import org.jetbrains.anko.act
import org.niray.imdemo.databinding.ActivityMainBinding @Suppress("MISSING_DEPENDENCY_CLASS")
class MainActivity : AppCompatActivity() { val mBean by lazy {
DataBean().apply {
userName.set("苏州独墅湖")
userAge.set(System.currentTimeMillis().toInt())
}
}
val binder by lazy { DataBindingUtil.setContentView<ActivityMainBinding>(act, R.layout.activity_main) } override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binder.userBean = mBean
postD()
} fun postD() {
window.decorView.postDelayed(object : Runnable {
override fun run() {
mBean.userName.set("I'm From Delayed")
mBean.userAge.set(System.currentTimeMillis().toInt())
binder.userBean = mBean
postD()
}
}, 1234)
}
}
<?xml version="1.0" encoding="utf-8"?>
<layout> <data> <variable
name="userBean"
type="org.niray.imdemo.DataBean" />
</data> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="org.niray.imdemo.MainActivity"> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{String.valueOf(userBean.userAge)}" /> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{userBean.userName}" /> </LinearLayout>
</layout>
http://www.jianshu.com/p/14281500bd74
http://kovenant.komponents.nl/android/features/
dependencies {
// ...
kapt 'com.android.databinding:compiler:2.2.0'//改为对应版本
}
kapt {
generateStubs = true
}
val binding = DataBindingUtil.setContentView<ActivityDataBindingBinding>(act, R.layout.activity_data_binding)
@Suppress("MISSING_DEPENDENCY_CLASS")
binding.userbean = UserBean("Grubby", "38")
android.DataBindingUtil的更多相关文章
- Android 中的mvvm
我们来了解一下MVVM模式与Databinding ,MVVM是一种模式,Databinding 是一种框架.DataBinding是一个实现数据和UI绑定的框架.而ViewModel和View可以通 ...
- android黑科技——完美解决界面逻辑的数据框架DataBinding(最新)的使用(二)
昨天我们一起学习了dataBinding的基础用法,我想你可能还停留在它只是不用再findViewById,其实不然,今天我们就来扩展延伸,看看这个框架到底有什么魔力让谷歌官方大力推崇.这里还没看昨天 ...
- Android MVP模式 谷歌官方代码解读
Google官方MVP Sample代码解读 关于Android程序的构架, 当前(2016.10)最流行的模式即为MVP模式, Google官方提供了Sample代码来展示这种模式的用法. Repo ...
- Android 常用布局视图
常用包 http://square.github.io/ EventBus Scroller 滚动 拖拽 # android.support.design.widget.CollapsingToolb ...
- Android官方数据绑定框架DataBinding
数据绑定框架给我们带来了更大的方便性,以前我们可能需要在Activity里写很多的findViewById,烦人的代码也增加了我们代码的耦合性,现在我们马上就可以抛弃那么多的findViewById. ...
- android mvvm初探
目前google的databinding library还处在rc版,其中编译器发挥了主要作用.目前也只是在android studio开发环境中支持. mvvm能够大大降低模块间的耦合度,在开发过程 ...
- Android mvp模式、mvvm模式
MVC和MVP的区别2007年08月08日 星期三 上午 09:23 MVC和MVP到底有什么区别呢? 从这幅图可以看到,我们可以看到在MVC里,View是可以直接访问Model的!从而,View里会 ...
- 完全掌握Android Data Binding
转载:http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015/0603/2992.html 来源 https://github.com/L ...
- 玩转Android之MVVM开发模式实战,炫酷的DataBinding!
C# 很早就有了MVVM的开发模式,Android手机中的MVVM一直到去年Google的I\O大会上才推出,姗姗来迟.MVVM这中开发模式的优点自不必多说,可以实现视图和逻辑代码的解耦,而且,按照G ...
随机推荐
- 微信支付WxpayAPI_php_v3 错误修改
微信sdk:WxpayAPI_php_v3 这是下载压缩包的目录结构. https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=11_1 ce ...
- BaseDAO使用
BaseDao接口的过人之处在于:一般是提供从数据库 增加.删除.修改记录.查询所有记录.查询符合某个条件记录.取得某条记录等方法的底层数据操作自定义类.由于我们可能操作多个数据库表,这样就需要为每个 ...
- llvm Array Bounds Check Elimination
http://www.knosof.co.uk/vulnerabilities/arraybnd.html http://www.cs.utsa.edu/dmz/techrep/2010/CS-TR- ...
- 登录sqlplus 后,显示问号 ????
登录sqlplus 后,显示 ???? SYS@orcl>startup ORACLE instance started. Total System Global Area 3290345472 ...
- How to extract a complete list of extension types within a directory?
Open the PowerShell Tool and Run the below command: Get-Childitem "D:\testfolder\" -Recurs ...
- android makefile文件批量拷贝文件的方法
该方法是shell 和makefile组合使用 wallpapers := $(shell ls packages/apps/hyst_apps/NewBingoLauncher_C/default_ ...
- MySQL 5.6新特性 -- crash-safe replication
在slave上有两个线程:io线程和sql线程io线程接收master的二进制日志信息并写入到本地的relay log中:sql线程执行本地relay log中的信息.io线程读取到的二进制日志当前位 ...
- Centos7安装SVN服务器
1.关闭防火墙systemctl stop firewalld.service 2.安装svn服务器yum install subversion 3.创建放置项目project的地方mkdir /sv ...
- 2.翻译系列:为EF Code-First设置开发环境(EF 6 Code-First系列)
原文链接:http://www.entityframeworktutorial.net/code-first/setup-entity-framework-code-first-environment ...
- [docker]使用quaaga实现(rip ospf)实现主机间容器互通
使用quaaga实现(rip ospf)实现主机间容器互通 - n1设置 brctl addbr br0 ip a a 10.1.1.1/24 br0 ip a a 10.1.1.1/24 dev b ...