<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable name="user" type="com.example.cunli.databing.web.User"/> </data>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@={user.email}"
android:id="@+id/email"
/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@={user.password}"
android:id="@+id/password"
android:layout_marginTop="10dp"/> <Button
android:layout_marginTop="30dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btn"
android:onClick="hello"
android:text="@string/app_name"/> </LinearLayout>
</layout> package com.example.cunli.databing.web; import android.databinding.BaseObservable;
import android.databinding.Bindable; import com.example.cunli.databing.BR; /**
* Created by winder on 2016/7/6.
*/
public class User extends BaseObservable {
public String email;
public String password; public User() {
} public User(String email, String password) {
this.email = email;
this.password = password;
} @Bindable
public String getPassword() {
return password;
} public void setPassword(String password) {
this.password = password;
notifyPropertyChanged(BR.password);
} @Bindable
public String getEmail() {
return email;
} public void setEmail(String email) {
this.email = email;
notifyPropertyChanged(BR.email);
} } package com.example.cunli.databing.activity; import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Toast; import com.example.cunli.databing.R;
import com.example.cunli.databing.databinding.ActivityMainBinding;
import com.example.cunli.databing.server.TeachLogServer;
import com.example.cunli.databing.web.CheckTeachLog;
import com.example.cunli.databing.web.TeachLog;
import com.example.cunli.databing.web.User; public class MainActivity extends AppCompatActivity { private TeachLogServer teachLogServer = new TeachLogServer();
User user; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main); user = new User("haliluya", "thankyoulord");
binding.setUser(user); } public void hello(View view){ Log.e("password","------getEmail------- "+user.getEmail()); Toast.makeText(this,user.getEmail()+"\t"+user.getPassword(), Toast.LENGTH_SHORT).show();
} }

DataBinding的更多相关文章

  1. android黑科技——完美解决界面逻辑的数据框架DataBinding(最新)的使用(二)

    昨天我们一起学习了dataBinding的基础用法,我想你可能还停留在它只是不用再findViewById,其实不然,今天我们就来扩展延伸,看看这个框架到底有什么魔力让谷歌官方大力推崇.这里还没看昨天 ...

  2. Debug Databinding Issues in WPF

    DataBinding is one of the most powerful features in WPF. But because it resolves the bindings at run ...

  3. Google官方关于Android架构中MVP模式的示例续-DataBinding

    基于前面的TODO示例,使用Data Binding库来显示数据并绑定UI元素的响应动作. 这个示例并未严格遵循 Model-View-ViewModel 或 Model-View-Presenter ...

  4. jface databinding:部分实现POJO对象的监测

    在前一篇博文<jface databinding/PojoBindable实现对POJO对象的支持  >中,已经知道直接对POJO对象进行修改,是不能被绑定的UI组件知道的,在上一篇文章中 ...

  5. DataBinding examples

    Databinding in Windows Forms demo (CSWinFormDataBinding) /************************************* Modu ...

  6. 【转】Native JavaScript Data-Binding

    原文转自:http://www.sellarafaeli.com/blog/native_javascript_data_binding Two-way data-binding is such an ...

  7. 配置Kotlin环境(DataBinding)

    1.安装Kotlin插件 在plugin中搜索kotlin,安装两个kotlin插件,重新启动Android Studio.2.build.gradle(project level) buildscr ...

  8. Android官方数据绑定框架DataBinding

    数据绑定框架给我们带来了更大的方便性,以前我们可能需要在Activity里写很多的findViewById,烦人的代码也增加了我们代码的耦合性,现在我们马上就可以抛弃那么多的findViewById. ...

  9. AngularJS学习--- AngularJS中数据双向绑定(two-way data-binding) orderBy step4

    1.切换工作目录 git checkout step- #切换分支,切换到第4步 npm start #启动项目 2.代码 app/index.html Search: <input ng-mo ...

  10. 复杂的databinding接受Ilist作为数据源

    Combobox控件绑定数据源时,List<T>可以作为数据源,但是List<String,Object> 不存在,我们有时候需要用Dictionary<String,o ...

随机推荐

  1. java.lang.OutOfMemoryError: Java heap space错误及处理办

    默认方式启动Eclipse时,有关启动时JVM参数是在Eclipse安装目录下的eclipse.ini文件中指定的.在命令行下,也可以通过参数-vmargs来达到此目的.其命令格式为:eclipse ...

  2. openstack私有云布署实践【7.2 keystone + memcache (办公网环境)】

    首先登录controller1创建keystone数据库,并赋于远程和本地访问的权限.   mysql -u root -p CREATE DATABASE keystone; GRANT ALL P ...

  3. 《JS权威指南学习总结--第九章 类和模板》

    内容要点: 一. 1.第六章详细介绍了JS对象,每个JS对象都是一个属性集合,相互之间没有任何联系.在JS中也可以定义对象的类,让每个对象都共享某些属性,这种"共享"的特性是非常有 ...

  4. Ubuntu彻底删除mysql

    删除 mysql sudo apt-get autoremove --purge mysql-server-5.0sudo apt-get remove mysql-serversudo apt-ge ...

  5. 3.通过js代码设置css样式

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. Windows下QT4.8.4编译环境的搭建(转载http://blog.csdn.net/bestgonghuibin/article/details/38933141)

    开始使用QT了,所以第一步就是把环境搭起来,这里小记一下,以免以后忘记. 1. 下载安装文件 要使用QT功能,那么必须要下载QT的源码,还必须要一个是用QT的编译环境,可以是VS2010,也可以是专用 ...

  7. MySql 安装报错 :Last Error:Unable to update security. Access denied for user 'root'@'localhost(useing password:YES)

    在网上查了一下,其实这个问题很好解决,. try again 然后current password  mysql是默认密码为空,不要填,记住不要填就ok了

  8. for计算100以内的偶数和

    #include "stdio.h" void main() { ,sum=; ;d++) { ==) { sum=sum+d; } }printf("100以内所有偶数 ...

  9. RPC框架基本原理(一):服务注册

    什么是RPC框架 RPC整个过程涉及四类对象:客户端.客户端代理.服务端和服务端代理.RPC要求客户端和服务端之间约定好调用接口和传输格式(如JSON,Xml等),客户端在调用该接口时,由客户端的代理 ...

  10. C# 处理图片 不规则图形裁剪

    最近项目要求实现不规则裁剪功能.本来想用html5的canvas在前端实现的,但是发现有点困难,以下为C#端对图对片的处理. 为了让大家知道下面内容是否是自己想要的,我先发效果图. 原图 通过下面代码 ...