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 ...
随机推荐
- cocos2d-x项目创建和打包
1.创建C++的cocos2d-x项目:cocos new test_cpp02 -p com.benmutou.helloWorld -l cpp -d projects C++未编译目录: C++ ...
- Go学习入门
1. 为什么要学习Go Go语言宣称为互联网时代的C语言,那她有那些特性值得我们必须学习呢: 并行与分布式支持.除了我们日常熟悉的进程和线程,Go语言中提供了协程coroutine,从而简化了并行开发 ...
- Python报错:ImportError: No module named src.data_layer
ImportError: No module named src.data_layer 解决方案: export PYTHONPATH=path/to/modules
- 04-树5 Root of AVL Tree + AVL树操作集
平衡二叉树-课程视频 An AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the tw ...
- 版本适配 sdk version MD
Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...
- 这些年我在技术路上做过最虚伪愚蠢的事情,就是在CSDN上刷屏赚分
现在似乎Github成了所谓技术人士的新宠,之前是博客,更早则是论坛. CSDN是众多技术论坛里比较突出的一个,人多高手也多,很多问题都能得到满意的回答. 谁都希望自己卓尔不群,我也不例外,我也想像那 ...
- Spring ActiveMQ 整合(三): 确认机制ACK(收到消息后,应该有一个回应也就是确认答复)
https://blog.csdn.net/dly1580854879/article/details/68490197
- centos7安装配置mysql5.6
1. 下载mysql的repo源 $ wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm 2. 安装mysql-co ...
- Fix Corrupt Blocks on HDFS
来自:http://centoshowtos.org/hadoop/fix-corrupt-blocks-on-hdfs/ How do I know if my hadoop hdfs filesy ...
- 从public void onPreviewFrame(byte[] data, Camera arg1)拿到Bitmap(收集)
private PreviewCallback pc = new PreviewCallback(){ public void onPreviewFrame(byte[] data, Camera a ...